What is the difference between isset() and __isset()?

后端 未结 7 445
广开言路
广开言路 2020-12-07 10:59

I need to know about magic function __isset() and normal function isset(). Actually what is the real difference between php language construct

7条回答
  •  -上瘾入骨i
    2020-12-07 11:36

    Magic functions are automatically invoked (triggered) when something happens. Normal functions have to be specifically invoked by your php code.

    In your case: __isset() will be automatically invoked when you have an isset() which is trying to get a non-accessible property.

    Example:

    root@folgore:/tmp/php# cat a.php 
    att1);
    
    // __isset will not be triggered:
    isset($obj->att2);
    
    root@folgore:/tmp/php# php a.php 
    __isset invoked for att1
    

提交回复
热议问题