You may think of the _ get magic method as the title first, but also the nest, but -- because I will need to use json_encode ($ obj) to output to JS access, so some_attr here can only be public. When $ obj-& amp; gt; some_attr is called, _ get cannot be used for this... you may think of the _ get magic method first when you see this title --
Because I will use json_encode ($ obj) to output to JS access, some_attr here can only be public.
When you call $ obj-> some_attr, you cannot use _ get...
Is there any more "magic" method ..?
I really don't want to get something like $ obj-> to_json...
Reply content:
You may think of the _ get magic method first when you see this title --
Because I will use json_encode ($ obj) to output to JS access, some_attr here can only be public.
When you call $ obj-> some_attr, you cannot use _ get...
Is there any more "magic" method ..?
I really don't want to get something like $ obj-> to_json...
You mean to specify the Members to be serialized within the class:
1) Let your class implement the Serializable interface (5.1 is supported), and write a serialize method to return json_encode data;
2) or implement the JsonSerializable interface (5.4 + ).
$name(); } protected function _var_a() { $this->var_a = 'a'; return $this->var_a; }}$test = new test();$test->_var_a;$str = json_encode($test);var_dump($str);
What is this requirement. Or am I wrong?
Direct external operations are not enough. Why bother.