I’m having issues with code that worked fine in PHP 5.3 and is now broken in PHP 5.4. The original environments where the code works are:
Ubuntu 11.04
Lighttpd 1.4.29
PHP 5.3
and
Mac OSX 10.7.4
Apache 2.0.63
PHP 5.3
and the new environment is:
Android 4.0.4
Lighttpd 1.4.29
PHP 5.4.4
I’ve boiled down the problem code to two simple files:
[test.class.php]
class Test {
public $testProp1;
function setTestProp1($value){
$this->testProp1 = $value;
return ($this->testProp1 != '') ? true : false;
}
function doSomething()
{
if( $this->testProp1 )
{ echo "Just do some " . $this->testProp1; }
else
{ echo "Just do nothing"; }
}
}
[debug.php]
error_reporting(E_ALL);
require "test.class.php";
$myTest = new Test();
$myTest->setTestProp1("foo");
$myTest->doSomething();
On the system with PHP 5.3, the output is:
Just do some foo
On the system with PHP 5.4, the output is:
Warning: Creating default object from empty value in /data/www/test.class.php on line 5
Notice: Undefined variable: this in /data/www/test.class.php on line 11
Notice: Trying to get property of non-object in /data/www/test.class.php on line 11
Just do nothing
Even if I change the error reporting level, I still get the warning and ‘Just do nothing’ in PHP 5.4. Not sure what the deal is, I’m totally stumped. Any help is appreciated!
Tried this on another install of PHP 5.4.4 on Mac OSX and it worked fine. We’re thinking something went wrong when we ported PHP to Android so we’ll have to revisit that process. In the future will definitely test more configurations before posting on SO.
Thanks everyone.