DETAILS

19/11/2008

PHP 5 Object References

PHP 5 seems to mostly fix the most glaring problem in PHP 4, its non-intuitive handling of references. However, this issue is more complicated than it sounds. For starters, here is one of the unit tests from PHP 5:

name = "I'm Foo!\n";
    }
}

$foo = new Foo;
echo $foo->name;
$bar = $foo;
$bar->name = "I'm Bar!\n";

// In ZE1, we would expect "I'm Foo!"
echo $foo->name;

?>

With PHP 4, this prints:

I'm Foo!
I'm Foo!

With PHP 5, it prints:

I'm Foo!
I'm Bar!

To get this result in PHP 4, you need to use the & operator:

Comments:


dmsty12@gmail.com says,
        

PDO provides a data-access abstraction layer, which means that, regardless of which database you're using, you use the same functions to issue queries and fetch data. PDO does not provide a database abstraction; it doesn't rewrite SQL or emulate missing features. You should use a full-blown abstraction layer if you need that facility.

PDO ships with PHP 5.1, and is available as a PECL extension for PHP 5.0; PDO requires the new OO features in the core of PHP 5, and so will not run with earlier versions of PHP.

 
01-01-2009