Bug #827: Assignment to $this
| From: | PHP Bug Database | Date: | Sat, 21 Feb 2004 21:18:46 +0000 |
| Subject: | Bug #827: Assignment to $this | ||
| Groups: | php.pear.qa | ||
| Request: | Send a blank email to pear-qa+get-616@lists.php.net to get a copy of this message | ||
From: pear-qa at lists dot php dot net
Operating system: Irrelevant
PHP version: 5.0.0b4 (beta4)
PHP Bug Type: Net_UserAgent_Mobile
Bug description: Assignment to $this
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_Mobile/Mobile/Common.php' :
/php/pear/Net_UserAgent_Mobile/Mobile/Common.php(90): $this =
$result;
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
}
--
Edit bug report at http://pear.php.net/bugs/bug.php?id=827&edit=2