$this in PHP5 breaks

$this in PHP5

In PHP4 anything can be assigned to the variable $this. But not anymore in PHP5.

Here is a code snipped from dracko
$this->dracko=new drackoManage();

Works fine in PHP4, and PHP5 stops with a fatal error: "Using $this when not in object context".

Ways to fix: rewrite your code to use another variable name than ‘this’ such as $_this.

When you call a static function in a Php class, it has the side-effect of wiping out the class context. Without the class context, you can’t make other calls to class members. In my case above, Php allowed me to break the class context (calling a non-static as static) without warning, which caused a perfectly legitimate class member function fail:

Instead, Php should warn: Calling a non-static member as static. This might not be what you meant to do.

Leave a Reply

Your email address will not be published. Required fields are marked *