CHAPTER 13 – COMPATIBILITY MODE – Casting Objects

In PHP 4, (int) $object returns 1 if the object has properties or 0 if the object has no properties. This is deprecated in PHP 5, where (int) $object always results in a 1. The following example shows this behavior: <?php /* Turn error reporting off */ error_reporting(0);

class bagel { }

$b = new bagel();

/* Cast to an integer */ if ((int) $b) { echo "Groovy baby!n"; }

/* Turn on compatibility mode and cast to an integer */ ini_set('zend.ze1_compatibility_mode', 1); if ((int) $b) { echo "Yeah baby!n"; } ?> In PHP 4, this example results in no output. However, in PHP 5 the output is Groovy baby!

Post Comment
Login to post comments