Re: $this manipulation in the constructor
| From: | Lorenzo Alberton | Date: | Tue, 24 Feb 2004 23:21:49 +0000 |
| Subject: | Re: $this manipulation in the constructor | ||
| Groups: | php.pear.qa | ||
| Request: | Send a blank email to pear-qa+get-638@lists.php.net to get a copy of this message | ||
Hi Toby,
by chance, did you tried the code below?
It has two little problems:
#1) [minor] the if() evaluates to true on 5.0.0RC-dev
#2) [bigger] the php parser will stop as soon as it 'sees'
the assignment to $this, not just in the case it encounters
it on the execution flow... hence, the script will die anyway :-(
Regards,
Lorenzo
===================================
I wrote some text pieces for the bug reports.
Please disagree until today 16:00 (Europe/Berlin time) if you have objections.
<snip>
## 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 method
is possible in PHP 4 but will throw an error with PHP 5 [1]. Please take care of
this issue for
PHP5 compatibility reasons.
[1] http://www.php.net/ChangeLog-5.php#5.0.0b4
Reproduceable code:
Affected are constructs like:
$this = ...;
Solutions:
The assignment to $this occurs mostly inside constructors
(<Your_Package_Name>()). You should provide a 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
}
</snip>
Regards,
Toby
--
Tobias Schlitt
a passion for php http://www.schlitt.info
===================================