Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
<?php
class safeBlaine {
public function foo($item = null) {
$this->protectedFoo('foo', 'bar', 'baz');
}
protected function protectedFoo() {
echo 'dont get here!';
exit;
}
}
class publicSafeBlaine extends safeBlaine {
public $parent;
public function __construct() {
$args = func_get_args();
$this->parent = array_shift($args);
call_user_func_array('parent::__construct', $args);
}
public function foo($item = null) {
$args = func_get_args();
$count = count($args);
$method = 'foo';
if ($count < 1 || $args[$count - 2] !== spl_object_hash($this)) {
return call_user_func_array(array($this->parent, $method), $args);
}
return call_user_func_array('parent::' . $method, $args);
}
public function protectedFoo($name = 'baz') {
$args = func_get_args();
$count = count($args);
$method = 'protectedFoo';
if ($count < 1 || $args[$count - 2] !== spl_object_hash($this)) {
return call_user_func_array(array($this->parent, $method), $args);
}
return call_user_func_array('parent::' . $method, $args);
}
}
class mockSafeBlaine extends publicSafeBlaine {
protected $_mocker;
public function __construct() {
$args = func_get_args();
array_unshift($args, $this);
$class = new ReflectionClass('publicSafeBlaine');
$this->_mocker = $class->newInstanceArgs($args);
}
public function foo($item = null) {
$args = func_get_args();
$args[] = spl_object_hash($this->_mocker);
return call_user_func_array(array($this->_mocker, 'foo'), $args);
}
public function protectedFoo($name = 'baz') {
echo 'get here';
exit;
}
}
$foo = new mockSafeBlaine('nikkie');
print_r($foo->foo('baz'));
<?php
class staticBlaine {
public static function foo($item = null) {
static::protectedFoo();
}
protected static function protectedFoo() {
echo 'dont get here!';
exit;
}
}
class publicStaticBlaine extends staticBlaine {
public static function foo($item = null) {
$args = func_get_args();
$count = count($args);
$method = 'foo';
if ($count < 1 || $args[$count - 1] !== '1f3870be274f6c49b3e31a0c6728957f') {
return call_user_func_array('mockSafeBlaine::' . $method, $args);
}
return call_user_func_array('parent::' . $method, $args);
}
public static function protectedFoo($name = 'baz') {
$args = func_get_args();
$count = count($args);
$method = 'protectedFoo';
if ($count < 1 || $args[$count - 1] !== '1f3870be274f6c49b3e31a0c6728957f') {
return call_user_func_array('mockSafeBlaine::' . $method, $args);
}
return call_user_func_array('parent::' . $method, $args);
}
}
class mockSafeBlaine extends publicStaticBlaine {
protected $_mocker;
public static function foo($item = null) {
$args = func_get_args();
$args[] = '1f3870be274f6c49b3e31a0c6728957f';
return call_user_func_array(array('publicStaticBlaine', 'foo'), $args);
}
public static function protectedFoo($name = 'baz') {
echo 'get here';
exit;
}
}
$foo = new mockSafeBlaine('nikkie');
print_r($foo->foo('baz'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.