Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In brief (since this is documented in various other places on the internet), magic methods are for setting and getting data. These calls </p> <pre><code>$this-&gt;setSomeThing('value'); $this-&gt;getSomeThing(); </code></pre> <p>are equivalent to these calls</p> <pre><code>$this-&gt;setData('some_thing','value'); $this-&gt;getData('some_thing'); </code></pre> <p>The string <code>'some_thing'</code> is a data key. To set and get data with a magic method is this key is CamelCased into 'SomeThing'. </p> <p>You can see <strong>all</strong> the data properties (and therefore derive the magic methods) with a parameterless call to 'getData'</p> <pre><code>var_dump( $this-&gt;getData() ); </code></pre> <p>Be careful with <code>var_dump</code> if you're not using <code>xDebug</code>, and many Magento objects are too large and/or too circular to fully display. If you're running into that problem, you can just peek at the keys with </p> <pre><code>var_dump( array_keys($this-&gt;getData()) ); </code></pre> <p>That's all magic methods are for in Magento — getting and setting data.</p> <p>Play around with this using a varien object, which is the object all Models and Blocks inherit from in Magento.</p> <pre><code>$o = new Varien_Object; $o-&gt;setData('foo','bar'); var_dump($o-&gt;getData('foo')); var_dump($o-&gt;getFoo('foo')); var_dump($o-&gt;getData()); </code></pre> <p>One last thing to keep in mind: If an object's class has a method defined with the same name as a magic method,the magic method is ignored. Sometimes the only way to know for sure if something is a magic method or a real method is to go look at the class definition. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload