Created
January 28, 2013 19:43
-
-
Save bayleedev/4658402 to your computer and use it in GitHub Desktop.
Will check to see if the call was made internally or externally.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace foo\bar\baz; | |
use ReflectionClass; | |
use ReflectionMethod; | |
use Exception; | |
class foo { | |
public function internalCall($class, $exception) { | |
$trace = $exception->getTrace(); | |
return count($trace) > 1 && isset($trace[1]['class']) && $trace[1]['class'] === $class; | |
} | |
public function bar() { | |
return $this->baz(); | |
} | |
public function baz() { | |
return $this->internalCall(__CLASS__, new Exception); | |
} | |
} | |
$foo = new foo(); | |
var_dump($foo->bar()); // true | |
var_dump($foo->baz()); // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment