Skip to content

Instantly share code, notes, and snippets.

@bobmagicii
Created January 31, 2013 18:29
Show Gist options
  • Save bobmagicii/4685064 to your computer and use it in GitHub Desktop.
Save bobmagicii/4685064 to your computer and use it in GitHub Desktop.
testing how good is_callable is about method accessibility.
<?php
class BobTest {
public function PublicMethod() { return; }
protected function ProtectedMethod() { return; }
private function PrivateMethod() { return; }
public function TestCallables() {
echo "testing myself...", PHP_EOL;
foreach((new ReflectionClass(__CLASS__))->getMethods() as $m) {
if(is_callable([$this,$m->name]))
echo "->{$m->name} yep", PHP_EOL;
else
echo "->{$m->name} nope", PHP_EOL;
}
}
}
$test = new BobTest;
$test->TestCallables();
echo "testing publicly...", PHP_EOL;
foreach((new ReflectionClass($test))->getMethods() as $m) {
if(is_callable([$test,$m->name]))
echo "->{$m->name} yep", PHP_EOL;
else
echo "->{$m->name} nope", PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment