Re: assign to $this
| From: | Lorenzo Alberton | Date: | Thu, 15 Apr 2004 21:55:48 +0000 |
| Subject: | Re: assign to $this | ||
| References: | 1 | Groups: | php.pear.qa |
| Request: | Send a blank email to pear-qa+get-1122@lists.php.net to get a copy of this message | ||
On Thu, 15 Apr 2004 18:35:41 +0200, Lukas Smith wrote:
>> I think it's time to face the "assign to $this" problem.
>>
>> The solution proposed by Toby in the QA reports
>> won't work, as php5 will die as soon as it *sees*
>> an assignment to $this, even if it never encounters
>> it in its workflow, so "if()" checks are out of the game.
>
> just as an FYI eval() would work as Derick pointed out to me.
Ok, I confirm that. The eval() solution [1] works :-)
Just a quick note:
The PEAR-QA proposed solution had the following "if" clause:
===========================
if (version_compare(phpversion(), '5.0.0') == -1)
===========================
this check evaluates to true on 5.0.0RC, though,
so I propose another one:
===========================
if (get_class($this) == 'lower_case_class_name') { //php4 lowers class names
// assign factoried method to $this for PHP 4
eval('$this = <ClassName>::factory($options);');
} else { //php5 is case sensitive
$msg = 'In PHP5 you must use the "<ClassName>::factory($params)"
method';
trigger_error($msg, E_USER_WARNING);
}
===========================
it should work.
HTH
Lorenzo
[1] http://marc.theaimsgroup.com/?l=php-dev&m=108204684332227&w=2