PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Networking » Net_UserAgent_Detect » Bug #826

Assignment to $this

Details

Submitted2004-02-21 21:17 UTC
Frompear-qa at lists dot php dot net
Assignedjrust
StatusClosed
PackageNet_UserAgent_Detect
PHP Version5.0.0b4 (beta4)
OSIrrelevant
Roadmaps(Not assigned)

Comments

[2004-02-21 21:17 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/Net_UserAgent/Detect.php' :
/php/pear/Net_UserAgent/Detect.php(207): $this =& Net_UserAgent_Detect::singleton();
/php/pear/Net_UserAgent/Detect.php(455): $this =& Net_UserAgent_Detect::singleton();
/php/pear/Net_UserAgent/Detect.php(479): $this =& Net_UserAgent_Detect::singleton();
/php/pear/Net_UserAgent/Detect.php(520): $this =& Net_UserAgent_Detect::singleton();
/php/pear/Net_UserAgent/Detect.php(549): $this =& Net_UserAgent_Detect::singleton();
/php/pear/Net_UserAgent/Detect.php(567): $this =& Net_UserAgent_Detect::singleton();
/php/pear/Net_UserAgent/Detect.php(589): $this =& Net_UserAgent_Detect::singleton();
/php/pear/Net_UserAgent/Detect.php(612): $this =& Net_UserAgent_Detect::singleton();
/php/pear/Net_UserAgent/Detect.php(634): $this =& Net_UserAgent_Detect::singleton();
/php/pear/Net_UserAgent/Detect.php(673): $this =& Net_UserAgent_Detect::singleton();
/php/pear/Net_UserAgent/Detect.php(703): $this =& Net_UserAgent_Detect::singleton();
/php/pear/Net_UserAgent/Detect.php(726): $this =& Net_UserAgent_Detect::singleton();
/php/pear/Net_UserAgent/Detect.php(748): $this =& Net_UserAgent_Detect::singleton();
/php/pear/Net_UserAgent/Detect.php(770): $this =& Net_UserAgent_Detect::singleton();
/php/pear/Net_UserAgent/Detect.php(792): $this =& Net_UserAgent_Detect::singleton();
/php/pear/Net_UserAgent/Detect.php(814): $this =& Net_UserAgent_Detect::singleton();
/php/pear/Net_UserAgent/Detect.php(842): $this =& Net_UserAgent_Detect::singleton();
/php/pear/Net_UserAgent/Detect.php(879): $this =& Net_UserAgent_Detect::singleton();
/php/pear/Net_UserAgent/Detect.php(912): $this =& Net_UserAgent_Detect::singleton();
/php/pear/Net_UserAgent/Detect.php(938): $this =& Net_UserAgent_Detect::singleton();

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
}

[2004-03-03 22:29 UTC] jrust at php dot net

This bug has been fixed in CVS.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pear.php.net.

In case this was a pear.php.net website problem, the change will show
up on the website in short time.

Thank you for the report, and for helping us make PEAR better.