Fast and Rich |
|
2024-11-24 |
|
|
23 |
|
|
Minor OOP Changes
- • var keyword is synonymous with public
- • old-style constructors still work
- • is_a() is going away, use instanceof operator
Converting Objects to strings in 5.2.x
<?php
echo (string)new stdClass;
// Results in Object id #1 before 5.2.x
// E_RECOVERABLE_ERROR in 5.2.x
// Use a __tostring() method to explicitly define
?>
Don't re-assign $this
<?php
class foo {
function bar($obj) {
$this = $obj; // Fatal error in 5.x
}
}
?>
Case kept in object info calls
<?php
class Foo {
function BaR() { }
}
class Xyz extends Foo { }
$a = new xyz;
echo get_class($a);
print_r(get_class_methods($a));
echo get_parent_class($a);
?>
A valid class is no longer empty
<?php
$a = new stdClass;
var_dump(empty($a)); // true in PHP 4, false in PHP 5
?>
E_STRICT on static method calls
<?php
class foo {
function bar() { echo "Bar"; }
}
foo::bar();
// Non-static method foo::bar() should not be called statically
?>
Redefining consts in 5.2.x
<?php
class foo {
const foo = "bar";
const foo = "baz"; // Fatal error in 5.2.x
}
echo foo::foo;
?>