private static function getVarName ($sFunction, $sFile, $iLine)
    {
        $sContent = file($sFile);
        $sLine = $sContent[$iLine - 1];
        preg_match("#$sFunction\s*\((.+)\)#", $sLine, $aMatches);

        // Let's count brackets to see how many of them actually belongs to the var name.
        // e.g.:    die(catch_param($this->getUser()->hasCredential("delete")));
        // We want: $this->getUser()->hasCredential("delete")
        $iMax = strlen($aMatches[1]);
        $sVarname = '';
        $iNb = 0;
        for ($i = 0; $i < $iMax; $i++) {
            $char = substr($aMatches[1], $i, 1);
            if ($char == '(') {
                $iNb++;
            } elseif ($char == ')') {
                $iNb--;
                if ($iNb < 0) {
                    break;
                }
            }
            $sVarname .= $char;
        }

        // $varname now holds the name of the passed variable ('$' included)
        // e.g.: catch_param($hello)
        //             => $sVarname = "$hello"
        // or the whole expression evaluated
        // e.g.: catch_param($this->getUser()->hasCredential("delete"))
        //             => $sVarname = "$this->getUser()->hasCredential(\"delete\")"
        return $sVarname;
    }
private static function getVarName ($sFunction, $sFile, $iLine)
    {
        $sContent = file($sFile);
        $sLine = $sContent[$iLine - 1];
        preg_match("#$sFunction\s*\((.+)\)#", $sLine, $aMatches);

        // Let's count brackets to see how many of them actually belongs to the var name.
        // e.g.:    die(catch_param($this->getUser()->hasCredential("delete")));
        // We want: $this->getUser()->hasCredential("delete")
        $iMax = strlen($aMatches[1]);
        $sVarname = '';
        $iNb = 0;
        for ($i = 0; $i < $iMax; $i++) {
            $char = substr($aMatches[1], $i, 1);
            if ($char == '(') {
                $iNb++;
            } elseif ($char == ')') {
                $iNb--;
                if ($iNb < 0) {
                    break;
                }
            }
            $sVarname .= $char;
        }

        // $varname now holds the name of the passed variable ('$' included)
        // e.g.: catch_param($hello)
        //             => $sVarname = "$hello"
        // or the whole expression evaluated
        // e.g.: catch_param($this->getUser()->hasCredential("delete"))
        //             => $sVarname = "$this->getUser()->hasCredential(\"delete\")"
        return $sVarname;
    }
private static function getVarName ( $ sFunction , $ sFile , $ iLine ) { $ sContent = file ( $ sFile ) ; $ sLine = $ sContent [ $ iLine - 1 ] ; preg_match ( "#$sFunction\s*\((.+)\)#" , $ sLine , $ aMatches ) ; // Let's count brackets to see how many of them actually belongs to the var name. // e.g.:    die(catch_param($this->getUser()->hasCredential("delete"))); // We want: $this->getUser()->hasCredential("delete") $ iMax = strlen ( $ aMatches [ 1 ] ) ; $ sVarname = '' ; $ iNb = 0 ; for ( $ i = 0 ; $ i < $ iMax ; $ i ++ ) { $ char = substr ( $ aMatches [ 1 ] , $ i , 1 ) ; if ( $ char == '(' ) { $ iNb ++ ; } elseif ( $ char == ')' ) { $ iNb -- ; if ( $ iNb < 0 ) { break ; } } $ sVarname .= $ char ; } // $varname now holds the name of the passed variable ('$' included) // e.g.: catch_param($hello) //             => $sVarname = "$hello" // or the whole expression evaluated // e.g.: catch_param($this->getUser()->hasCredential("delete")) //             => $sVarname = "$this->getUser()->hasCredential(\"delete\")" return $ sVarname ; }
Return the name of the first parameter of the penultimate function call.

TODO bug if multiple calls in the same line…

@see http://stackoverflow.com/a/6837836
@author Sebastián Grignoli
@author Geoffroy Aubry

@param string $sFunction function called
@param string $sFile file containing a call to $sFunction
@param int $iLine line in $sFile containing a call to $sFunction
@return string the name of the first parameter of the penultimate function call.
Return the name of the first parameter of the penultimate function call .