While working in a project written by some one else ,there's a Function which retrieves some Data's and it's return is the Array with Data.
function getSomedata()
{
//Get some data
return Array();
}
And on the code this function is tested in many Places as
if(getSomedata())
getSomedata();
Without editing every piece of code ,can i get notified from php if that Function is called from an IF Statement and return a Boolean instead of the Array with Data.
Theoretically, you could use backtracing to figure out which code called a piece of code and read and introspect the code to figure out if the function was called in an if
statement. But I'm not even going to go into the details of how to do this, because it's utter madness.
if (function()) function()
is an anti-pattern, broken code, bad, bad, bad. You need to fix this misuse instead of fighting it with more madness. If that's used in a lot of places, bite the bullet and fix it once instead of having to deal with it forever.
I think the best thing you can do is just to use $GLOBALS to check if the Array is set:
function getSomedata()
{
if(!empty($GLOBALS['Arr']))
return $Arr;
//Get some data
return $Arr;
}
Something like that... It will work for you if data is not changing during script execution. But I suggest you to fix your code.
getSomedata()
to a variable, then check if that variable is empty - ziad-saab 2012-05-28 08:08