how to access a variable and called a class method at the same time
Hmmm,not sure how to do this
i have a public variable
public $meta;
I'm calling the method in my application like this
$auth->meta_data('rental_access');
Now I'm curious is to how I can get the information from it. How can I access the $meta variable information based on the switch logic from the method?
In my a开发者_JS百科pplication I want to use the information from the $meta variable to make some more logic statements hmmm something like
if ($auth->meta-data('rental_access') == 1) { //or maybe have it look for a true/false thing
//do this
} else {
// then do this
}
I would avoid combining that explicitely. Rather use the tried and proven fluent interface approach. You simply make each method return $this
:
function meta_data($item) {
...
return $this;
}
This allows you to write:
if ($auth->meta_data("rental_access")->meta == 2) {
It's usually used for calling multiple functions in a chains. But this likewise acceptable.
Obviously this is only applicable to procedures which don't already return
a result of their own.
Why not modify your meta_data()
method, so it returns the new value of your meta
property :
public function meta_data($item)
{
// your existing code, here
return $this->meta;
}
And, then, call it storing the returned value into a variable :
$new_value = $auth->meta_data('rental_access');
精彩评论