Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overloading in php

Tags:

php

php-5.3

Can any one tell what does below given lines means?

The lines below are copied from PHP manual:

Note:

It is not possible to use overloaded properties in other language constructs than isset(). This means if empty() is called on an overloaded property, the overloaded method is not called.

To workaround that limitation, the overloaded property must be copied into a local variable in the scope and then be handed to empty().

BUT this is not true that we cant call empty() on overloaded properties, when i called empty() , it triggered __isset()

like image 583
Poonam Bhatt Avatar asked Jun 16 '12 13:06

Poonam Bhatt


1 Answers

It is a documentation bug:

<?php
class PropNameReturn {
    function __isset($propname){
          return true;

    }
    function __get($propname){
          echo 'Yes, it IS called!'.PHP_EOL;
          return $propname;
    }
}
$o = new PropNameReturn();
var_dump(empty($o->this_prop_name));
//Yes, it IS called!
//bool(false)
$b = new stdClass();
var_dump(empty($b->this_prop_name));
//bool(true)
like image 180
Wrikken Avatar answered Oct 03 '22 19:10

Wrikken