parent
c3f5aca1a8
commit
bdea6f77cc
7 changed files with 236 additions and 0 deletions
@ -0,0 +1,21 @@ |
|||||||
|
<?php |
||||||
|
class C |
||||||
|
{ |
||||||
|
function __call($name, $values) |
||||||
|
{ |
||||||
|
$values[0][0] = 'changed'; |
||||||
|
} |
||||||
|
} |
||||||
|
function main() { |
||||||
|
$a = array('original'); |
||||||
|
$b = array('original'); |
||||||
|
|
||||||
|
$hack =& $b[0]; |
||||||
|
|
||||||
|
$c = new C; |
||||||
|
$c->f($a); |
||||||
|
$c->f($b); |
||||||
|
|
||||||
|
var_dump($a, $b); |
||||||
|
} |
||||||
|
|
||||||
@ -0,0 +1,41 @@ |
|||||||
|
--TEST-- |
||||||
|
ZE2 __call() |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
|
||||||
|
class Caller { |
||||||
|
public $x = array(1, 2, 3); |
||||||
|
|
||||||
|
function __call($m, $a) { |
||||||
|
echo "Method $m called:\n"; |
||||||
|
var_dump($a); |
||||||
|
return $this->x; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
function main() { |
||||||
|
$foo = new Caller(); |
||||||
|
$a = $foo->test(1, '2', 3.4, true); |
||||||
|
var_dump($a); |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
Method test called: |
||||||
|
array(4) { |
||||||
|
[0]=> |
||||||
|
int(1) |
||||||
|
[1]=> |
||||||
|
string(1) "2" |
||||||
|
[2]=> |
||||||
|
float(3.4) |
||||||
|
[3]=> |
||||||
|
bool(true) |
||||||
|
} |
||||||
|
array(3) { |
||||||
|
[0]=> |
||||||
|
int(1) |
||||||
|
[1]=> |
||||||
|
int(2) |
||||||
|
[2]=> |
||||||
|
int(3) |
||||||
|
} |
||||||
@ -0,0 +1,20 @@ |
|||||||
|
--TEST-- |
||||||
|
ZE2 __call() signature check |
||||||
|
--SKIPIF-- |
||||||
|
<?php die('skip'); ?> |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
|
||||||
|
class Test { |
||||||
|
function __call() { |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
function main() { |
||||||
|
$test = new Test(); |
||||||
|
$test->test(); |
||||||
|
} |
||||||
|
|
||||||
|
?> |
||||||
|
--EXPECTF-- |
||||||
|
Fatal error: Method Test::__call() must take exactly 2 arguments in %s__call_002.php on line %d |
||||||
@ -0,0 +1,31 @@ |
|||||||
|
--TEST-- |
||||||
|
Force pass-by-reference to __call (Incompatible) |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
class C |
||||||
|
{ |
||||||
|
function __call($name, $values) |
||||||
|
{ |
||||||
|
$values[0][0] = 'changed'; |
||||||
|
} |
||||||
|
} |
||||||
|
function main() { |
||||||
|
$a = array('original'); |
||||||
|
$b = array('original'); |
||||||
|
|
||||||
|
$c = new C; |
||||||
|
$c->f($a); |
||||||
|
$c->f($b); |
||||||
|
|
||||||
|
var_dump($a, $b); |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
array(1) { |
||||||
|
[0]=> |
||||||
|
string(7) "changed" |
||||||
|
} |
||||||
|
array(1) { |
||||||
|
[0]=> |
||||||
|
string(7) "changed" |
||||||
|
} |
||||||
@ -0,0 +1,44 @@ |
|||||||
|
--TEST-- |
||||||
|
When __call() is invoked via ::, ensure current scope's __call() is favoured over the specified class's __call(). |
||||||
|
--SKIPIF-- |
||||||
|
<?php die('skip'); ?> |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
class A { |
||||||
|
function __call($strMethod, $arrArgs) { |
||||||
|
echo "In " . __METHOD__ . "($strMethod, array(" . implode(',',$arrArgs) . "))\n"; |
||||||
|
var_dump($this); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
class B extends A { |
||||||
|
function __call($strMethod, $arrArgs) { |
||||||
|
echo "In " . __METHOD__ . "($strMethod, array(" . implode(',',$arrArgs) . "))\n"; |
||||||
|
var_dump($this); |
||||||
|
} |
||||||
|
|
||||||
|
function test() { |
||||||
|
A::test1(1,'a'); |
||||||
|
B::test2(1,'a'); |
||||||
|
self::test3(1,'a'); |
||||||
|
parent::test4(1,'a'); |
||||||
|
} |
||||||
|
} |
||||||
|
function main() { |
||||||
|
$b = new B(); |
||||||
|
$b->test(); |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
In B::__call(test1, array(1,a)) |
||||||
|
object(B)#1 (0) { |
||||||
|
} |
||||||
|
In B::__call(test2, array(1,a)) |
||||||
|
object(B)#1 (0) { |
||||||
|
} |
||||||
|
In B::__call(test3, array(1,a)) |
||||||
|
object(B)#1 (0) { |
||||||
|
} |
||||||
|
In B::__call(test4, array(1,a)) |
||||||
|
object(B)#1 (0) { |
||||||
|
} |
||||||
@ -0,0 +1,40 @@ |
|||||||
|
--TEST-- |
||||||
|
When __call() is invoked via ::, ensure private implementation of __call() in superclass is accessed without error. |
||||||
|
--SKIPIF-- |
||||||
|
<?php die('skip'); ?> |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
class A { |
||||||
|
private function __call($strMethod, $arrArgs) { |
||||||
|
echo "In " . __METHOD__ . "($strMethod, array(" . implode(',',$arrArgs) . "))\n"; |
||||||
|
var_dump($this); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
class B extends A { |
||||||
|
function test() { |
||||||
|
A::test1(1,'a'); |
||||||
|
B::test2(1,'a'); |
||||||
|
self::test3(1,'a'); |
||||||
|
parent::test4(1,'a'); |
||||||
|
} |
||||||
|
} |
||||||
|
function main() { |
||||||
|
$b = new B(); |
||||||
|
$b->test(); |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECTF-- |
||||||
|
Warning: The magic method A::__call() must have public visibility in %s__call_005.php on line 3 |
||||||
|
In A::__call(test1, array(1,a)) |
||||||
|
object(B)#1 (0) { |
||||||
|
} |
||||||
|
In A::__call(test2, array(1,a)) |
||||||
|
object(B)#1 (0) { |
||||||
|
} |
||||||
|
In A::__call(test3, array(1,a)) |
||||||
|
object(B)#1 (0) { |
||||||
|
} |
||||||
|
In A::__call(test4, array(1,a)) |
||||||
|
object(B)#1 (0) { |
||||||
|
} |
||||||
@ -0,0 +1,39 @@ |
|||||||
|
--TEST-- |
||||||
|
ZE2 The new constructor/destructor is called |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
|
||||||
|
class early { |
||||||
|
function __construct() { |
||||||
|
echo __CLASS__ . "::" . __FUNCTION__ . "\n"; |
||||||
|
} |
||||||
|
function __destruct() { |
||||||
|
echo __CLASS__ . "::" . __FUNCTION__ . "\n"; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
class late { |
||||||
|
function __construct() { |
||||||
|
echo __CLASS__ . "::" . __FUNCTION__ . "\n"; |
||||||
|
} |
||||||
|
function __destruct() { |
||||||
|
echo __CLASS__ . "::" . __FUNCTION__ . "\n"; |
||||||
|
} |
||||||
|
} |
||||||
|
function main() { |
||||||
|
$t = new early(); |
||||||
|
$t->__construct(); |
||||||
|
unset($t); |
||||||
|
$t = new late(); |
||||||
|
//unset($t); delay to end of script |
||||||
|
|
||||||
|
echo "Done\n"; |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
early::__construct |
||||||
|
early::__construct |
||||||
|
early::__destruct |
||||||
|
late::__construct |
||||||
|
Done |
||||||
|
late::__destruct |
||||||
Loading…
Reference in new issue