2007-02-27
php4, php5, objects and cloning
David, though I feel your pain with this, I think the PHP5 code is much closer to what other languages do and is therefor the following the “least surprise” rule. However, breaking existing code with a compiler/interpreter upgrade is of course a bad thing. But in this very special case, I think that the plus side puts in more weight than the negative side.
When reading PHP code others wrote (which is what I do with PHP most of the time, with just a few hundred lines of PHP code ever written by myself), I always wondered why
$f=new Foobar();
$a=$f;
$a->do_something();
if ( $a->fetch() != $f->fetch() ) {
echo "they differ\n";
}
would ever print anything. At least until I hit myself with the php-cluebat again, remembering that $a=$object assigns a copy of $object to $a, not a reference like most other languages tend to do.
