Sunday 15 April 2012

oop - PHP - methods of a object -


I am a Java developer who is trying to understand this PHP behavior. I have implemented the following methods:

  error_log (get_class ($ a). "\ N", 3, "c: \ my-errors.log"); Error_log (print_r (get_class_methods ($ a), true). "\ N", 3, "c: \ my-errors.log");   

printed

  Mage_Catalog_Model_Product Array ([0] = & gt; MilnostorID ... [90] = & gt; GetWeight [91] = & GetOptionInstance [9 2] = & gt; GoProduct Option Convention [93] = & gt; Adoption [94] = getOptionById [95] = & gt; Matching Options [96] = & gt; IIS Virtual ... [182] = flag digital)   

But the next line is executed (without errors) is a method that is not explicitly in the list of methods that I print earlier: / P>

  $ a-> getOption ()   

So, how is this possible? How can I know all the methods of an object? There is no way to know what is the way to execute the "next line code" - because there are several "million" functions in this project and I can not understand which one is being executed . > Maybe it can help you, I'm working with Magento 1.7 and the code I'm talking about is

  \ app \ code \ Core \ mage \ bundle \ model \ product \ type .php @shakeSelections   

Thanks a lot!

The information that you want to see is the short version รข ???? If you call a non-existent method on a PHP object, the __ call method is enforced by giving PHP developers the opportunity to apply meta-programming features.

You are interested magento feature magic sets and gates. Magento objects that come from Varien_Object (usually models and blocks), they get the magic and set methods, the above mentioned __ Call method

you

  $ array = $ object- & gt; Can get an array of data in an object with getData ();   

This array looks like

  array ('foo' = & gt; 'bar', 'other_field' = 'gtc:' baz ')   

You can access the values ​​of foo and another_field with calls to aforementioned magic getters < Pre> echo $ this-> GetFoo (); Echo $ the-> GetAnotherField (); You can use the magic setter

  $ this-> SetFoo ('no time now') can set new values ); $ This- & gt; SetAnotherField ('now falcon');   

The setters are also chain-enabled.

  $ this-> Setfu ('again!') - & gt; SetAnotherField ('badge to badge');   

If no data attribute is set, then gates will return null this means that

  $ object - & gt; Receive ... $ object-> Set ... ...   

Returns may be coming from a genuine method, or may be coming from a magic data setter and recipient.

No comments:

Post a Comment