Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.0.4

Bug #829 Assignment to $this
Submitted: 2004-02-21 21:22 UTC
From: pear-qa at lists dot php dot net Assigned: fredericpoeydomenge
Status: Closed Package: Var_Dump
PHP Version: 5.0.0b4 (beta4) OS: Irrelevant
Roadmaps: (Not assigned)    
Subscription  


 [2004-02-21 21:22 UTC] pear-qa at lists dot php dot net
Description: ------------ ## from the PEAR QA team ## ## quality-assurance related ## ## PHP 5 compatibility issue ## Dear package maintainer, your package makes use of the assignement of new values to $this. This methodis possible in PHP 4 but will throw an error with PHP 5 [1]. Please take care of this issue forPHP5 compatibility reasons. Please answer to this bugreport directly through the PEAR bug tracker or the mailinglist pear-qa@lists.php.net . With kind regards, PEAR QA Team [1] http://www.php.net/ChangeLog-5.php#5.0.0b4 Reproduce code: --------------- FILE: '/php/pear/Var_Dump.php' : /php/pear/Var_Dump.php(275): $this = & new Var_Dump; /php/pear/Var_Dump.php(302): $this = & new Var_Dump; Expected result: ---------------- Solutions: The assignment to $this occurs mostly inside constructors (<Your_Package_Name>()). You should provide an static factory() or singleton() method for this. To provide backwards compatibility you should work around the affected code pieces. This can be done by a version check: if (version_compare(phpversion(), "5.0.0") == -1) { // assign factoried method to this for PHP 4 // $this =& <Your_Package_Name>::factory(); $this =& <Your_Package_Name>::singleton(); } else { // error handling for PHP5 // user has to use the factory()/singleton() method }

Comments

 [2004-04-25 17:00 UTC] pmjones
The following code replaces the display() and r_display() methods to correct the $this usage. Appears to work in PHP4, have not tested on PHP5 (no access to a PHP5 installation). // {{{ display() /** * display() - Displays informations about a variable * * This method displays informations about the values of a variable on a * graphical way, arrays and objects being explored recursively * * @param $variable A variable to explore * @param string $except If not empty, name of the key not to * explore, to avoid parsing references to itself */ function display($variable = '', $except = '', $displayMode = false, $options=0) { if (!isset($this) or get_class($this) != 'var_dump') { $obj = & new Var_Dump; if ($displayMode !== false) { $obj->_VarDumpConfGlobal['displayMode'] = $displayMode; $obj->setSkin($displayMode); } } else { $obj = & $this; } echo $obj->r_display($variable, $except, $displayMode, $options); } // }}} // {{{ r_display() /** * r_display() - Returns informations about a variable, ready to be printed * * This method returns informations about the values of a variable, ready * to be printed on a graphical way, arrays and objects being explored * recursively * * @param $variable A variable to explore * @param string $except If not empty, name of the key not to * explore, to avoid parsing references to itself */ function r_display($variable = '', $except = '', $displayMode = false, $options=0) { if (!isset($this) or get_class($this) != 'var_dump') { $obj = & new Var_Dump; if ($displayMode !== false) { $obj->_VarDumpConfGlobal['displayMode'] = $displayMode; $obj->setSkin($displayMode); } } else { $obj = & $this; } $obj->_VarDumpConfGlobal['displayOptions'] = $options; $obj->_populate($variable, $except); $obj->_generateFontTags(); switch($obj->_VarDumpConfGlobal['displayMode']) { case VAR_DUMP_DISPLAY_MODE_TEXT: return $obj->_formatTableTEXT($obj- >_VarDumpArray[0],false); break; case VAR_DUMP_DISPLAY_MODE_HTML_TEXT: return $obj->_formatTableTEXT($obj- >_VarDumpArray[0],true); break; case VAR_DUMP_DISPLAY_MODE_HTML_TABLE: default: return $obj->_formatTableHTML($obj- >_VarDumpArray); break; } } // }}}
 [2004-04-28 14:36 UTC] frederic dot poeydomenge at free dot fr
Thank you for your bug report. This issue has been fixed in the latest released version of the package, which you can download at http://pear.php.net/packages.php Complete refactoring of the class in v0.9 : the package makes no more use of the assignement of new values to $this, and is using instead singleton/factory constructor.