PHP 8.4.24 Released!

Voting

: min(nine, two)?
(Example: nine)

The Note You're Voting On

BruceB
10 years ago
This is not going to go down as you might expect it should (even if you play smart and require/include_once):

<?php
if(function_exists('my_function'))
{
   throw new Exception("'my_function' is already defined!");
}

function my_function()
{
   // Do the work here
}
?>

This, however does work:

<?php
if( ! function_exists('my_function'))
{
   function my_function()
   {
      // Do the work here
   }
}
else
{
   throw new Exception("'my_function' is already defined!");
}
?>

Does it have anything to do with PHP parse/execute phases or global/local scope or those curly brackets or something else, I have no idea, but the latter ugly son works, while the former bombs out claiming that 'my_function' is already defined.

Thought this might save someone a few minutes of debugging time...

<< Back to user notes page

To Top