Skip to content

Instantly share code, notes, and snippets.

@bayleedev
Created January 28, 2013 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bayleedev/4658402 to your computer and use it in GitHub Desktop.
Save bayleedev/4658402 to your computer and use it in GitHub Desktop.
Will check to see if the call was made internally or externally.
<?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