Skip to main content
Commonmark migration
Source Link

I'm thinking about creating a class that uses method chaining. What I'm trying to achieve is the type the output of methods, based if the methods are chained or not.

Example 1:

##Example 1: $var = $instance->user($id);

Returns an array with the necessary information.

Example 2:

##Example 2: $var = $instance->user($id)->action($arg);

I want the chained method in front of user() to just pass the argument $id to the next method and for it not to output anything. Then the method action() grabs the $id and return what's asked.

How can I achieve this?

The reason I want don't want to make user() return its normal result code is because I intend to use this in an API wrapper. Returning the "normal" user() will cost me an additional X-Rate-Limit call. If I could spare this call, and just pass the parameter $id to the second method, that would be the ideal.

I'm thinking about creating a class that uses method chaining. What I'm trying to achieve is the type the output of methods, based if the methods are chained or not.

##Example 1: $var = $instance->user($id);

Returns an array with the necessary information.

##Example 2: $var = $instance->user($id)->action($arg);

I want the chained method in front of user() to just pass the argument $id to the next method and for it not to output anything. Then the method action() grabs the $id and return what's asked.

How can I achieve this?

The reason I want don't want to make user() return its normal result code is because I intend to use this in an API wrapper. Returning the "normal" user() will cost me an additional X-Rate-Limit call. If I could spare this call, and just pass the parameter $id to the second method, that would be the ideal.

I'm thinking about creating a class that uses method chaining. What I'm trying to achieve is the type the output of methods, based if the methods are chained or not.

Example 1:

$var = $instance->user($id);

Returns an array with the necessary information.

Example 2:

$var = $instance->user($id)->action($arg);

I want the chained method in front of user() to just pass the argument $id to the next method and for it not to output anything. Then the method action() grabs the $id and return what's asked.

How can I achieve this?

The reason I want don't want to make user() return its normal result code is because I intend to use this in an API wrapper. Returning the "normal" user() will cost me an additional X-Rate-Limit call. If I could spare this call, and just pass the parameter $id to the second method, that would be the ideal.

Explanatory title
Link
halfer
  • 20.2k
  • 20
  • 110
  • 207

How to control return based if methods are chained or not Can a Fluent Interface method in PHP detect where it is in the chain?

Ah, this is what you want, not an explanation of how chaining works
Source Link
halfer
  • 20.2k
  • 20
  • 110
  • 207

I'm thinking about creating a class that uses method chaining. What I'm trying to achieve is the type the output of methods, based if the methods are chained or not.

##Example 1: $var = $instance->user($id);

Returns an array with the necessary information.

##Example 2: $var = $instance->user($id)->action($arg);

Having aI want the chained method in front of user(), makes it to just pass the argument $id to the next method and for it doesn'tnot to output anything. Then the method action() grabs the $id and return what's asked.

How can I achieve this?

The reason I want don't want to make user() return its normal result code is because I intend to use this in an API wrapper. Returning the "normal" user() will cost me an additional X-Rate-Limit call. If I could spare this call, and just pass the parameter $id to the second method, that would be the ideal.

I'm thinking about creating a class that uses method chaining. What I'm trying to achieve is the type the output of methods, based if the methods are chained or not.

##Example 1: $var = $instance->user($id);

Returns an array with the necessary information.

##Example 2: $var = $instance->user($id)->action($arg);

Having a chained method in front of user(), makes it just pass the argument $id to the next method and it doesn't output anything. Then the method action() grabs the $id and return what's asked.

How can I achieve this?

The reason I want don't want to make user() return its normal result code is because I intend to use this in an API wrapper. Returning the "normal" user() will cost me an additional X-Rate-Limit call. If I could spare this call, and just pass the parameter $id to the second method, that would be the ideal.

I'm thinking about creating a class that uses method chaining. What I'm trying to achieve is the type the output of methods, based if the methods are chained or not.

##Example 1: $var = $instance->user($id);

Returns an array with the necessary information.

##Example 2: $var = $instance->user($id)->action($arg);

I want the chained method in front of user() to just pass the argument $id to the next method and for it not to output anything. Then the method action() grabs the $id and return what's asked.

How can I achieve this?

The reason I want don't want to make user() return its normal result code is because I intend to use this in an API wrapper. Returning the "normal" user() will cost me an additional X-Rate-Limit call. If I could spare this call, and just pass the parameter $id to the second method, that would be the ideal.

Better explained for what I need this code.
Source Link
Loading
Source Link
Loading