svn: /phpdoc/en/trunk/ appendices/migration56/new-features.xml language/oop5/magic.xml reference/var/functions/var-dump.xml

From: Date: Thu, 28 Aug 2014 05:28:06 +0000
Subject: svn: /phpdoc/en/trunk/ appendices/migration56/new-features.xml language/oop5/magic.xml reference/var/functions/var-dump.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-12744@lists.php.net to get a copy of this message
aharvey Thu, 28 Aug 2014 05:28:06 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=334638 Log: Document __debugInfo(). Changed paths: U phpdoc/en/trunk/appendices/migration56/new-features.xml U phpdoc/en/trunk/language/oop5/magic.xml U phpdoc/en/trunk/reference/var/functions/var-dump.xml Modified: phpdoc/en/trunk/appendices/migration56/new-features.xml =================================================================== --- phpdoc/en/trunk/appendices/migration56/new-features.xml 2014-08-28 05:20:57 UTC (rev 334637) +++ phpdoc/en/trunk/appendices/migration56/new-features.xml 2014-08-28 05:28:06 UTC (rev 334638) @@ -307,6 +307,50 @@ </informalexample> </sect2> + <sect2 xml:id="migration56.new-features.debuginfo"> + <title><literal>__debugInfo()</literal></title> + + <para> + The <link linkend="language.oop5.magic.debuginfo">__debugInfo()</link> + magic method has been added to allow objects to change the properties and + values that are shown when the object is output using + <function>var_dump</function>. + </para> + + <informalexample> + <programlisting role="php"> +<![CDATA[ +<?php +class C { + private $prop; + + public function __construct($val) { + $this->prop = $val; + } + + public function __debugInfo() { + return [ + 'propSquared' => $this->prop ** 2, + ]; + } +} + +var_dump(new C(42)); +?> +]]> + </programlisting> + &example.outputs; + <screen> +<![CDATA[ +object(C)#1 (1) { + ["propSquared"]=> + int(1764) +} +]]> + </screen> + </informalexample> + </sect2> + <sect2 xml:id="migration56.new-features.gost"> <title>gost-crypto hash algorithm</title> Modified: phpdoc/en/trunk/language/oop5/magic.xml =================================================================== --- phpdoc/en/trunk/language/oop5/magic.xml 2014-08-28 05:20:57 UTC (rev 334637) +++ phpdoc/en/trunk/language/oop5/magic.xml 2014-08-28 05:28:06 UTC (rev 334638) @@ -16,8 +16,9 @@ <link linkend="object.wakeup">__wakeup()</link>, <link linkend="object.tostring">__toString()</link>, <link linkend="object.invoke">__invoke()</link>, - <link linkend="object.set-state">__set_state()</link> and - <link linkend="object.clone">__clone()</link> + <link linkend="object.set-state">__set_state()</link>, + <link linkend="object.clone">__clone()</link> and + <link linkend="object.debuginfo">__debugInfo()</link> are magical in PHP classes. You cannot have functions with these names in any of your classes unless you want the magic functionality associated @@ -288,6 +289,56 @@ </screen> </example> </sect2> + + <sect2 xml:id="language.oop5.magic.debuginfo"> + <title><link linkend="object.debuginfo">__debugInfo()</link></title> + <methodsynopsis xml:id="object.debuginfo"> + <type>array</type><methodname>__debugInfo</methodname> + <void/> + </methodsynopsis> + <para> + This method is called by <function>var_dump</function> when dumping an + object to get the properties that should be shown. If the method isn't + defined on an object, then all public, protected and private properties + will be shown. + </para> + <para> + This feature was added in PHP 5.6.0. + </para> + <example> + <title>Using <link linkend="object.debuginfo">__debugInfo()</link></title> + <programlisting role="php"> +<![CDATA[ +<?php +class C { + private $prop; + + public function __construct($val) { + $this->prop = $val; + } + + public function __debugInfo() { + return [ + 'propSquared' => $this->prop ** 2, + ]; + } +} + +var_dump(new C(42)); +?> +]]> + </programlisting> + &example.outputs; + <screen> +<![CDATA[ +object(C)#1 (1) { + ["propSquared"]=> + int(1764) +} +]]> + </screen> + </example> + </sect2> </sect1> <!-- Keep this comment at the end of the file Modified: phpdoc/en/trunk/reference/var/functions/var-dump.xml =================================================================== --- phpdoc/en/trunk/reference/var/functions/var-dump.xml 2014-08-28 05:20:57 UTC (rev 334637) +++ phpdoc/en/trunk/reference/var/functions/var-dump.xml 2014-08-28 05:28:06 UTC (rev 334638) @@ -20,8 +20,10 @@ explored recursively with values indented to show structure. </simpara> <simpara> - In PHP 5 all public, private and protected properties of objects will be - returned in the output. + All public, private and protected properties of objects will be returned in + the output unless the object implements a + <link linkend="language.oop5.magic.debuginfo">__debugInfo()</link> method + (implemented in PHP 5.6.0). </simpara> &tip.ob-capture; </refsect1> @@ -111,6 +113,7 @@ <member><function>print_r</function></member> <member><function>debug_zval_dump</function></member> <member><function>var_export</function></member> + <member><link linkend="language.oop5.magic.debuginfo">__debugInfo()</link></member> </simplelist> </para> </refsect1>

« previous php.doc.cvs (#12744) next »