Search code examples
phpnotice

PHP not issuing any notice for undefined variable if the variable is passing to empty() or isset()


<?php

function myFunction($yesNname) { } 

empty($noName);
print_r($noName);
isset($noName);

myFunction($noName);

output:

PHP Notice:  Undefined variable: noName ... on line 6 // print_r
PHP Notice:  Undefined variable: noName ... on line 9 // myFunction

The undefined variable is used in empty() and isset(). But PHP didn't issue notice about it. Why PHP shows discrimination to some function? How can I write such type of function?


Solution

  • Neither isset() nor empty() are functions. As the manual explains:

    this is a language construct and not a function

    To get this behaviour you'd need to tweak the PHP source code written in C.

    It's possible that you can also get this behaviour with a PHP extension, but you'd also need to write it in C and install it in your server.

    Update: