02nd Mar 2008

PHP 4.x annoying bug related to $this keyword

Did you know PHP 4.x cannot take reference from $this? So, code below won’t work:

$reference = &$this;

It took me about 30 minutes to figure out what exactly was wrong with my code. So, I hope this post will help somebody else to avoid the problem.

What I did to fix it. Just added another property named “reference” to class and initialized it right after creating class instance. If anybody knows another way - please let me know.

Thank you.

Leave a Reply

Close
E-mail It