diff options
Diffstat (limited to 'tests')
70 files changed, 2188 insertions, 0 deletions
diff --git a/tests/classes/__call_003.phpt b/tests/classes/__call_003.phpt new file mode 100644 index 0000000000..c7aa95cb04 --- /dev/null +++ b/tests/classes/__call_003.phpt @@ -0,0 +1,33 @@ +--TEST-- +Force pass-by-reference to __call +--FILE-- +<?php + class C + { + function __call($name, $values) + { + $values[0][0] = 'changed'; + } + } + + $a = array('original'); + + $b = array('original'); + $hack =& $b[0]; + + $c = new C; + $c->f($a); + $c->f($b); + + var_dump($a, $b); +?> +--EXPECTF-- +array(1) { + [0]=> + string(8) "original" +} +array(1) { + [0]=> + &string(7) "changed" +} + diff --git a/tests/classes/autoload_007.phpt b/tests/classes/autoload_007.phpt new file mode 100644 index 0000000000..5652c120cc --- /dev/null +++ b/tests/classes/autoload_007.phpt @@ -0,0 +1,15 @@ +--TEST-- +Ensure instanceof does not trigger autoload. +--FILE-- +<?php + function __autoload($name) + { + echo "In autoload: "; + var_dump($name); + } + + $a = new stdClass; + var_dump($a instanceof UndefC); +?> +--EXPECTF-- +bool(false) diff --git a/tests/classes/autoload_008.phpt b/tests/classes/autoload_008.phpt new file mode 100644 index 0000000000..75a9cd0520 --- /dev/null +++ b/tests/classes/autoload_008.phpt @@ -0,0 +1,26 @@ +--TEST-- +Ensure catch blocks for unknown exception types do not trigger autoload. +--FILE-- +<?php + function __autoload($name) + { + echo "In autoload: "; + var_dump($name); + } + + function f() + { + throw new Exception(); + } + try { + f(); + } + catch (UndefC $u) { + echo "In UndefClass catch block.\n"; + } + catch (Exception $e) { + echo "In Exception catch block. Autoload should not have been triggered.\n"; + } +?> +--EXPECTF-- +In Exception catch block. Autoload should not have been triggered. diff --git a/tests/classes/autoload_009.phpt b/tests/classes/autoload_009.phpt new file mode 100644 index 0000000000..46f6055fef --- /dev/null +++ b/tests/classes/autoload_009.phpt @@ -0,0 +1,20 @@ +--TEST-- +Ensure type hints for unknown types do not trigger autoload. +--FILE-- +<?php + function __autoload($name) + { + echo "In autoload: "; + var_dump($name); + } + + function f(UndefClass $x) + { + } + f(new stdClass); +?> +--EXPECTF-- + +Catchable fatal error: Argument 1 passed to f() must be an instance of UndefClass, instance of stdClass given, called in %s + + diff --git a/tests/classes/autoload_010.phpt b/tests/classes/autoload_010.phpt new file mode 100644 index 0000000000..104f6888c8 --- /dev/null +++ b/tests/classes/autoload_010.phpt @@ -0,0 +1,18 @@ +--TEST-- +Ensure implements does trigger autoload. +--FILE-- +<?php + function __autoload($name) + { + echo "In autoload: "; + var_dump($name); + } + + class C implements UndefI + { + } +?> +--EXPECTF-- +In autoload: string(6) "UndefI" + +Fatal error: Interface 'UndefI' not found in %s on line %d diff --git a/tests/classes/autoload_011.phpt b/tests/classes/autoload_011.phpt new file mode 100644 index 0000000000..86858d5f1d --- /dev/null +++ b/tests/classes/autoload_011.phpt @@ -0,0 +1,18 @@ +--TEST-- +Ensure extends does trigger autoload. +--FILE-- +<?php + function __autoload($name) + { + echo "In autoload: "; + var_dump($name); + } + + class C extends UndefBase + { + } +?> +--EXPECTF-- +In autoload: string(9) "UndefBase" + +Fatal error: Class 'UndefBase' not found in %s on line %d diff --git a/tests/classes/autoload_012.phpt b/tests/classes/autoload_012.phpt new file mode 100644 index 0000000000..cc73f3fd8d --- /dev/null +++ b/tests/classes/autoload_012.phpt @@ -0,0 +1,15 @@ +--TEST-- +Ensure callback methods in unknown classes trigger autoload. +--FILE-- +<?php + function __autoload($name) + { + echo "In autoload: "; + var_dump($name); + } + call_user_func("UndefC::test"); +?> +--EXPECTF-- +In autoload: string(6) "UndefC" + +Warning: call_user_func() expects parameter 1 to be valid callback, string given in %s on line %d diff --git a/tests/classes/autoload_013.phpt b/tests/classes/autoload_013.phpt new file mode 100644 index 0000000000..4309cea176 --- /dev/null +++ b/tests/classes/autoload_013.phpt @@ -0,0 +1,22 @@ +--TEST-- +Ensure the ReflectionClass constructor triggers autoload. +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php + function __autoload($name) + { + echo "In autoload: "; + var_dump($name); + } + + try { + new ReflectionClass("UndefC"); + } + catch (ReflectionException $e) { + echo $e->getMessage(); + } +?> +--EXPECTF-- +In autoload: string(6) "UndefC" +Class UndefC does not exist diff --git a/tests/classes/autoload_014.phpt b/tests/classes/autoload_014.phpt new file mode 100644 index 0000000000..a3f04b7b57 --- /dev/null +++ b/tests/classes/autoload_014.phpt @@ -0,0 +1,22 @@ +--TEST-- +Ensure the ReflectionMethod constructor triggers autoload. +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php + function __autoload($name) + { + echo "In autoload: "; + var_dump($name); + } + + try { + new ReflectionMethod("UndefC::test"); + } + catch (ReflectionException $e) { + echo $e->getMessage(); + } +?> +--EXPECTF-- +In autoload: string(6) "UndefC" +Class UndefC does not exist diff --git a/tests/classes/autoload_015.phpt b/tests/classes/autoload_015.phpt new file mode 100644 index 0000000000..2b14a0de05 --- /dev/null +++ b/tests/classes/autoload_015.phpt @@ -0,0 +1,22 @@ +--TEST-- +Ensure the ReflectionProperty constructor triggers autoload. +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php + function __autoload($name) + { + echo "In autoload: "; + var_dump($name); + } + + try { + new ReflectionProperty('UndefC', 'p'); + } + catch (ReflectionException $e) { + echo $e->getMessage(); + } +?> +--EXPECTF-- +In autoload: string(6) "UndefC" +Class UndefC does not exist diff --git a/tests/classes/autoload_016.phpt b/tests/classes/autoload_016.phpt new file mode 100644 index 0000000000..60263ba95a --- /dev/null +++ b/tests/classes/autoload_016.phpt @@ -0,0 +1,23 @@ +--TEST-- +Ensure ReflectionClass::getProperty() triggers autoload +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php + function __autoload($name) + { + echo "In autoload: "; + var_dump($name); + } + + $rc = new ReflectionClass("stdClass"); + + try { + $rc->getProperty("UndefC::p"); + } catch (ReflectionException $e) { + echo $e->getMessage(); + } +?> +--EXPECTF-- +In autoload: string(6) "undefc" +Class undefc does not exist diff --git a/tests/classes/autoload_017.phpt b/tests/classes/autoload_017.phpt new file mode 100644 index 0000000000..26de9fd3ae --- /dev/null +++ b/tests/classes/autoload_017.phpt @@ -0,0 +1,23 @@ +--TEST-- +Ensure ReflectionClass::implementsInterface triggers autoload. +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php + function __autoload($name) + { + echo "In autoload: "; + var_dump($name); + } + + $rc = new ReflectionClass("stdClass"); + + try { + $rc->implementsInterface("UndefI"); + } catch (ReflectionException $e) { + echo $e->getMessage(); + } +?> +--EXPECTF-- +In autoload: string(6) "UndefI" +Interface UndefI does not exist
\ No newline at end of file diff --git a/tests/classes/autoload_018.phpt b/tests/classes/autoload_018.phpt new file mode 100644 index 0000000000..59e20e2a60 --- /dev/null +++ b/tests/classes/autoload_018.phpt @@ -0,0 +1,48 @@ +--TEST-- +Ensure __autoload() allows for recursive calls if the class name differs. +--FILE-- +<?php + function __autoload($name) + { + echo "IN: " . __METHOD__ . "($name)\n"; + + static $i = 0; + if ($i++ > 10) { + echo "-> Recursion detected - as expected.\n"; + return; + } + + class_exists('UndefinedClass' . $i); + + echo "OUT: " . __METHOD__ . "($name)\n"; + } + + var_dump(class_exists('UndefinedClass0')); +?> +--EXPECTF-- +IN: __autoload(UndefinedClass0) +IN: __autoload(UndefinedClass1) +IN: __autoload(UndefinedClass2) +IN: __autoload(UndefinedClass3) +IN: __autoload(UndefinedClass4) +IN: __autoload(UndefinedClass5) +IN: __autoload(UndefinedClass6) +IN: __autoload(UndefinedClass7) +IN: __autoload(UndefinedClass8) +IN: __autoload(UndefinedClass9) +IN: __autoload(UndefinedClass10) +IN: __autoload(UndefinedClass11) +-> Recursion detected - as expected. +OUT: __autoload(UndefinedClass10) +OUT: __autoload(UndefinedClass9) +OUT: __autoload(UndefinedClass8) +OUT: __autoload(UndefinedClass7) +OUT: __autoload(UndefinedClass6) +OUT: __autoload(UndefinedClass5) +OUT: __autoload(UndefinedClass4) +OUT: __autoload(UndefinedClass3) +OUT: __autoload(UndefinedClass2) +OUT: __autoload(UndefinedClass1) +OUT: __autoload(UndefinedClass0) +bool(false) + diff --git a/tests/classes/autoload_019.phpt b/tests/classes/autoload_019.phpt new file mode 100644 index 0000000000..783632013b --- /dev/null +++ b/tests/classes/autoload_019.phpt @@ -0,0 +1,14 @@ +--TEST-- +Ensure __autoload() recursion is guarded for multiple lookups of same class using difference case. +--FILE-- +<?php + function __autoload($name) + { + echo __FUNCTION__ . " $name\n"; + class_exists("undefinedCLASS"); + } + + class_exists("unDefinedClass"); +?> +--EXPECTF-- +__autoload unDefinedClass diff --git a/tests/classes/autoload_020.phpt b/tests/classes/autoload_020.phpt new file mode 100644 index 0000000000..a88e561238 --- /dev/null +++ b/tests/classes/autoload_020.phpt @@ -0,0 +1,17 @@ +--TEST-- +Ensure __autoload() is triggered during unserialization. +--FILE-- +<?php + function __autoload($name) + { + echo "in autoload: $name\n"; + } + + var_dump(unserialize('O:1:"C":0:{}')); +?> +--EXPECTF-- +in autoload: C +object(__PHP_Incomplete_Class)#%d (1) { + ["__PHP_Incomplete_Class_Name"]=> + string(1) "C" +} diff --git a/tests/classes/constants_basic_001.phpt b/tests/classes/constants_basic_001.phpt new file mode 100644 index 0000000000..74b0fcdf48 --- /dev/null +++ b/tests/classes/constants_basic_001.phpt @@ -0,0 +1,89 @@ +--TEST-- +Class constant declarations +--FILE-- +<?php + define('DEFINED', 1234); + $def = 456; + define('DEFINED_TO_VAR', $def); + define('DEFINED_TO_UNDEF_VAR', $undef); + + class C + { + const c0 = UNDEFINED; + + const c1 = 1, c2 = 1.5; + const c3 = + 1, c4 = + 1.5; + const c5 = -1, c6 = -1.5; + + const c7 = __LINE__; + const c8 = __FILE__; + const c9 = __CLASS__; + const c10 = __METHOD__; + const c11 = __FUNCTION__; + + const c12 = DEFINED; + const c13 = DEFINED_TO_VAR; + const c14 = DEFINED_TO_UNDEF_VAR; + + const c15 = "hello1"; + const c16 = 'hello2'; + const c17 = C::c16; + const c18 = self::c17; + } + + echo "\nAttempt to access various kinds of class constants:\n"; + var_dump(C::c0); + var_dump(C::c1); + var_dump(C::c2); + var_dump(C::c3); + var_dump(C::c4); + var_dump(C::c5); + var_dump(C::c6); + var_dump(C::c7); + var_dump(C::c8); + var_dump(C::c9); + var_dump(C::c10); + var_dump(C::c11); + var_dump(C::c12); + var_dump(C::c13); + var_dump(C::c14); + var_dump(C::c15); + var_dump(C::c16); + var_dump(C::c17); + var_dump(C::c18); + + echo "\nExpecting fatal error:\n"; + var_dump(C::c19); + + echo "\nYou should not see this."; +?> +--EXPECTF-- + +Notice: Undefined variable: undef in %s on line 5 + +Attempt to access various kinds of class constants: + +Notice: Use of undefined constant UNDEFINED - assumed 'UNDEFINED' in %s on line %d +string(9) "UNDEFINED" +int(1) +float(1.5) +int(1) +float(1.5) +int(-1) +float(-1.5) +int(15) +string(%d) "%s" +string(1) "C" +string(1) "C" +string(0) "" +int(1234) +int(456) +NULL +string(6) "hello1" +string(6) "hello2" +string(6) "hello2" +string(6) "hello2" + +Expecting fatal error: + +Fatal error: Undefined class constant 'c19' in %s on line 53 diff --git a/tests/classes/constants_basic_002.phpt b/tests/classes/constants_basic_002.phpt new file mode 100644 index 0000000000..0e53ca97c8 --- /dev/null +++ b/tests/classes/constants_basic_002.phpt @@ -0,0 +1,32 @@ +--TEST-- +Basic class support - defining and reading a class constant. +--FILE-- +<?php + class aclass + { + const myConst = "hello"; + } + + echo "\nRead class constant.\n"; + var_dump(aclass::myConst); + + echo "\nFail to read class constant from instance.\n"; + $myInstance = new aclass(); + var_dump($myInstance->myConst); + + echo "\nClass constant not visible in object var_dump.\n"; + var_dump($myInstance) +?> +--EXPECTF-- + +Read class constant. +string(5) "hello" + +Fail to read class constant from instance. + +Notice: Undefined property: aclass::$myConst in %s on line 12 +NULL + +Class constant not visible in object var_dump. +object(aclass)#%d (0) { +} diff --git a/tests/classes/constants_basic_003.inc b/tests/classes/constants_basic_003.inc new file mode 100644 index 0000000000..be193e64f8 --- /dev/null +++ b/tests/classes/constants_basic_003.inc @@ -0,0 +1,5 @@ +<?php +class A { + const MY_CONST = "hello from A"; +} +?>
\ No newline at end of file diff --git a/tests/classes/constants_basic_003.phpt b/tests/classes/constants_basic_003.phpt new file mode 100644 index 0000000000..052af8573e --- /dev/null +++ b/tests/classes/constants_basic_003.phpt @@ -0,0 +1,28 @@ +--TEST-- +Ensure class properties and constants can be defined in terms of constants that are not known at compile time. +--FILE-- +<?php + include 'constants_basic_003.inc'; + class B + { + public static $a = A::MY_CONST; + public static $c = C::MY_CONST; + const ca = A::MY_CONST; + const cc = C::MY_CONST; + } + + class C + { + const MY_CONST = "hello from C"; + } + + var_dump(B::$a); + var_dump(B::$c); + var_dump(B::ca); + var_dump(B::cc); +?> +--EXPECTF-- +string(12) "hello from A" +string(12) "hello from C" +string(12) "hello from A" +string(12) "hello from C" diff --git a/tests/classes/constants_basic_004.phpt b/tests/classes/constants_basic_004.phpt new file mode 100644 index 0000000000..cade66844b --- /dev/null +++ b/tests/classes/constants_basic_004.phpt @@ -0,0 +1,99 @@ +--TEST-- +Test properties with array default values using class constants as keys and values. +--FILE-- +<?php + class X + { + // Static and instance array using class constants + public static $sa_x = array(B::KEY => B::VALUE); + public $a_x = array(B::KEY => B::VALUE); + } + + class B + { + const KEY = "key"; + const VALUE = "value"; + + // Static and instance array using class constants with self + public static $sa_b = array(self::KEY => self::VALUE); + public $a_b = array(self::KEY => self::VALUE); + } + + class C extends B + { + // Static and instance array using class constants with parent + public static $sa_c_parent = array(parent::KEY => parent::VALUE); + public $a_c_parent = array(parent::KEY => parent::VALUE); + + // Static and instance array using class constants with self (constants should be inherited) + public static $sa_c_self = array(self::KEY => self::VALUE); + public $a_c_self = array(self::KEY => self::VALUE); + + // Should also include inherited properties from B. + } + + echo "\nStatic properties:\n"; + var_dump(X::$sa_x, B::$sa_b, C::$sa_b, C::$sa_c_parent, C::$sa_c_self); + + echo "\nInstance properties:\n"; + $x = new x; + $b = new B; + $c = new C; + var_dump($x, $b, $c); +?> +--EXPECTF-- + +Static properties: +array(1) { + ["key"]=> + string(5) "value" +} +array(1) { + ["key"]=> + string(5) "value" +} +array(1) { + ["key"]=> + string(5) "value" +} +array(1) { + ["key"]=> + string(5) "value" +} +array(1) { + ["key"]=> + string(5) "value" +} + +Instance properties: +object(X)#%d (1) { + ["a_x"]=> + array(1) { + ["key"]=> + string(5) "value" + } +} +object(B)#%d (1) { + ["a_b"]=> + array(1) { + ["key"]=> + string(5) "value" + } +} +object(C)#%d (3) { + ["a_c_parent"]=> + array(1) { + ["key"]=> + string(5) "value" + } + ["a_c_self"]=> + array(1) { + ["key"]=> + string(5) "value" + } + ["a_b"]=> + array(1) { + ["key"]=> + string(5) "value" + } +} diff --git a/tests/classes/constants_basic_005.phpt b/tests/classes/constants_basic_005.phpt new file mode 100644 index 0000000000..c840f5385a --- /dev/null +++ b/tests/classes/constants_basic_005.phpt @@ -0,0 +1,16 @@ +--TEST-- +Test constants with default values based on other constants. +--FILE-- +<?php + class C + { + const CONST_2 = self::CONST_1; + const CONST_1 = self::BASE_CONST; + const BASE_CONST = 'hello'; + } + var_dump(C::CONST_1, C::CONST_2); +?> +--EXPECTF-- +string(5) "hello" +string(5) "hello" + diff --git a/tests/classes/constants_basic_006.phpt b/tests/classes/constants_basic_006.phpt new file mode 100644 index 0000000000..73cf0ef3a9 --- /dev/null +++ b/tests/classes/constants_basic_006.phpt @@ -0,0 +1,43 @@ +--TEST-- +Ensure class constants are not evaluated when a class is looked up to resolve inheritance during runtime. +--FILE-- +<?php + class C + { + const X = E::A; + public static $a = array(K => D::V, E::A => K); + } + + eval('class D extends C { const V = \'test\'; }'); + + class E extends D + { + const A = "hello"; + } + + define('K', "nasty"); + + var_dump(C::X, C::$a, D::X, D::$a, E::X, E::$a); +?> +--EXPECTF-- +string(5) "hello" +array(2) { + ["nasty"]=> + string(4) "test" + ["hello"]=> + string(5) "nasty" +} +string(5) "hello" +array(2) { + ["nasty"]=> + string(4) "test" + ["hello"]=> + string(5) "nasty" +} +string(5) "hello" +array(2) { + ["nasty"]=> + string(4) "test" + ["hello"]=> + string(5) "nasty" +} diff --git a/tests/classes/constants_error_001.phpt b/tests/classes/constants_error_001.phpt new file mode 100644 index 0000000000..9bb5533d7e --- /dev/null +++ b/tests/classes/constants_error_001.phpt @@ -0,0 +1,13 @@ +--TEST-- +Error case: duplicate class constant definition +--FILE-- +<?php + class myclass + { + const myConst = "hello"; + const myConst = "hello again"; + } +?> +--EXPECTF-- + +Fatal error: Cannot redefine class constant myclass::myConst in %s on line 5 diff --git a/tests/classes/constants_error_002.phpt b/tests/classes/constants_error_002.phpt new file mode 100644 index 0000000000..be27971b87 --- /dev/null +++ b/tests/classes/constants_error_002.phpt @@ -0,0 +1,12 @@ +--TEST-- +Error case: class constant as an array +--FILE-- +<?php + class myclass + { + const myConst = array(); + } +?> +--EXPECTF-- + +Fatal error: Arrays are not allowed in class constants in %s on line 4 diff --git a/tests/classes/constants_error_003.phpt b/tests/classes/constants_error_003.phpt new file mode 100644 index 0000000000..c67768c809 --- /dev/null +++ b/tests/classes/constants_error_003.phpt @@ -0,0 +1,20 @@ +--TEST-- +Basic class support - attempting to pass a class constant by reference. +--FILE-- +<?php + class aclass + { + const myConst = "hello"; + } + + function f(&$a) + { + $a = "changed"; + } + + f(aclass::myConst); + var_dump(aclass::myConst); +?> +--EXPECTF-- + +Fatal error: Only variables can be passed by reference in %s on line 12 diff --git a/tests/classes/constants_error_004.phpt b/tests/classes/constants_error_004.phpt new file mode 100644 index 0000000000..03e67258a6 --- /dev/null +++ b/tests/classes/constants_error_004.phpt @@ -0,0 +1,13 @@ +--TEST-- +Class constant whose initial value refereces a non-existent class +--FILE-- +<?php + class C + { + const c1 = D::hello; + } + + $a = new C(); +?> +--EXPECTF-- +Fatal error: Class 'D' not found in %s on line %d diff --git a/tests/classes/constants_error_005.phpt b/tests/classes/constants_error_005.phpt new file mode 100644 index 0000000000..1283783de7 --- /dev/null +++ b/tests/classes/constants_error_005.phpt @@ -0,0 +1,12 @@ +--TEST-- +Error case: class constant as an encapsed containing a variable +--FILE-- +<?php + class myclass + { + const myConst = "$myVar"; + } +?> +--EXPECTF-- + +Parse error: %s in %s on line %d diff --git a/tests/classes/constants_error_006.phpt b/tests/classes/constants_error_006.phpt new file mode 100644 index 0000000000..f3f14b867b --- /dev/null +++ b/tests/classes/constants_error_006.phpt @@ -0,0 +1,16 @@ +--TEST-- +Basic class support - attempting to modify a class constant by assignment +--FILE-- +<?php + class aclass + { + const myConst = "hello"; + } + + echo "\nTrying to modify a class constant directly - should be parse error.\n"; + aclass::myConst = "no!!"; + var_dump(aclass::myConst); +?> +--EXPECTF-- + +Parse error: %s in %s on line %d diff --git a/tests/classes/constants_error_007.phpt b/tests/classes/constants_error_007.phpt new file mode 100644 index 0000000000..4be8d885f5 --- /dev/null +++ b/tests/classes/constants_error_007.phpt @@ -0,0 +1,15 @@ +--TEST-- +Basic class support - attempting to create a reference to a class constant +--FILE-- +<?php + class aclass + { + const myConst = "hello"; + } + + echo "\nAttempting to create a reference to a class constant - should be parse error.\n"; + $a = &aclass::myConst; +?> +--EXPECTF-- + +Parse error: %s in %s on line %d diff --git a/tests/classes/final_ctor3.phpt b/tests/classes/final_ctor3.phpt new file mode 100644 index 0000000000..d37e864e2d --- /dev/null +++ b/tests/classes/final_ctor3.phpt @@ -0,0 +1,15 @@ +--TEST-- +Ensure implicit final inherited old-style constructor cannot be overridden. +--FILE-- +<?php + class A { + final function A() { } + } + class B extends A { + } + class C extends B { + function B() { } + } +?> +--EXPECTF-- +Fatal error: Cannot override final method A::B() in %s on line 9 diff --git a/tests/classes/inheritance_005.phpt b/tests/classes/inheritance_005.phpt new file mode 100644 index 0000000000..b6f47b2a66 --- /dev/null +++ b/tests/classes/inheritance_005.phpt @@ -0,0 +1,42 @@ +--TEST-- +Check for inherited old-style constructor. +--FILE-- +<?php + class A + { + function A() + { + echo "In " . __METHOD__ . "\n"; + } + } + + class B extends A + { + } + + class C extends B + { + } + + + echo "About to construct new B: "; + $b = new B; + echo "About to invoke implicit B::B(): "; + $b->B(); + + echo "\nAbout to construct new C: "; + $c = new C; + echo "About to invoke implicit C::B(): "; + $c->B(); + echo "About to invoke implicit C::C(): "; + $c->C(); +?> +--EXPECTF-- +About to construct new B: In A::A +About to invoke implicit B::B(): In A::A + +About to construct new C: In A::A +About to invoke implicit C::B(): In A::A +About to invoke implicit C::C(): In A::A + + diff --git a/tests/classes/method_call_variation_001.phpt b/tests/classes/method_call_variation_001.phpt new file mode 100644 index 0000000000..dd43cfd1cb --- /dev/null +++ b/tests/classes/method_call_variation_001.phpt @@ -0,0 +1,37 @@ +--TEST-- +In $a->$b[Y](), $b[Y] represents a method name on $a. But in $a->X[Y](), $a->X[Y] represents a global function name. +--FILE-- +<?php + class C + { + function foo($a, $b) + { + echo "Called C::foo($a, $b)\n"; + } + } + + $c = new C; + + $functions[0] = 'foo'; + $functions[1][2][3][4] = 'foo'; + + $c->$functions[0](1, 2); + $c->$functions[1][2][3][4](3, 4); + + + function foo($a, $b) + { + echo "Called global foo($a, $b)\n"; + } + + $c->functions[0] = 'foo'; + $c->functions[1][2][3][4] = 'foo'; + + $c->functions[0](5, 6); + $c->functions[1][2][3][4](7, 8); +?> +--EXPECTF-- +Called C::foo(1, 2) +Called C::foo(3, 4) +Called global foo(5, 6) +Called global foo(7, 8) diff --git a/tests/classes/new_001.phpt b/tests/classes/new_001.phpt new file mode 100644 index 0000000000..8ef8a71e0f --- /dev/null +++ b/tests/classes/new_001.phpt @@ -0,0 +1,46 @@ +--TEST-- +Confirm difference between assigning new directly and by reference. +--FILE-- +<?php + echo "Compile-time strict error message should precede this.\n"; + + class Inc + { + private static $counter = 0; + function __construct() + { + $this->id = ++Inc::$counter; + } + } + + $f = new Inc(); + $k =& $f; + echo "\$f initially points to the first object:\n"; + var_dump($f); + + echo "Assigning new object directly to \$k affects \$f:\n"; + $k = new Inc(); + var_dump($f); + + echo "Assigning new object by ref to \$k removes it from \$f's reference set, so \$f is unchanged:\n"; + $k =& new Inc(); + var_dump($f); +?> +--EXPECTF-- +Strict Standards: Assigning the return value of new by reference is deprecated in %s on line 23 +Compile-time strict error message should precede this. +$f initially points to the first object: +object(Inc)#%d (1) { + ["id"]=> + int(1) +} +Assigning new object directly to $k affects $f: +object(Inc)#%d (1) { + ["id"]=> + int(2) +} +Assigning new object by ref to $k removes it from $f's reference set, so $f is unchanged: +object(Inc)#%d (1) { + ["id"]=> + int(2) +} diff --git a/tests/classes/property_override_privateStatic_private.phpt b/tests/classes/property_override_privateStatic_private.phpt new file mode 100644 index 0000000000..ddd2e5d1ac --- /dev/null +++ b/tests/classes/property_override_privateStatic_private.phpt @@ -0,0 +1,33 @@ +--TEST-- +Redeclare inherited private static property as private. +--FILE-- +<?php + class A + { + private static $p = "A::p (static)"; + static function showA() + { + echo self::$p . "\n"; + } + } + + class B extends A + { + private $p = "B::p"; + function showB() + { + echo $this->p . "\n"; + } + } + + + A::showA(); + + $b = new B; + $b->showA(); + $b->showB(); +?> +--EXPECTF-- +A::p (static) +A::p (static) +B::p diff --git a/tests/classes/property_override_privateStatic_privateStatic.phpt b/tests/classes/property_override_privateStatic_privateStatic.phpt new file mode 100644 index 0000000000..d7d645fd0a --- /dev/null +++ b/tests/classes/property_override_privateStatic_privateStatic.phpt @@ -0,0 +1,32 @@ +--TEST-- +Redeclare inherited private static property as private static. +--FILE-- +<?php + class A + { + private static $p = "A::p (static)"; + static function showA() + { + echo self::$p . "\n"; + } + } + + class B extends A + { + private static $p = "B::p (static)"; + static function showB() + { + echo self::$p . "\n"; + } + } + + + A::showA(); + + B::showA(); + B::showB(); +?> +--EXPECTF-- +A::p (static) +A::p (static) +B::p (static) diff --git a/tests/classes/property_override_privateStatic_protected.phpt b/tests/classes/property_override_privateStatic_protected.phpt new file mode 100644 index 0000000000..d4732166c6 --- /dev/null +++ b/tests/classes/property_override_privateStatic_protected.phpt @@ -0,0 +1,33 @@ +--TEST-- +Redeclare inherited private static property as protected. +--FILE-- +<?php + class A + { + private static $p = "A::p (static)"; + static function showA() + { + echo self::$p . "\n"; + } + } + + class B extends A + { + protected $p = "B::p"; + function showB() + { + echo $this->p . "\n"; + } + } + + + A::showA(); + + $b = new B; + $b->showA(); + $b->showB(); +?> +--EXPECTF-- +A::p (static) +A::p (static) +B::p diff --git a/tests/classes/property_override_privateStatic_protectedStatic.phpt b/tests/classes/property_override_privateStatic_protectedStatic.phpt new file mode 100644 index 0000000000..169ff9a377 --- /dev/null +++ b/tests/classes/property_override_privateStatic_protectedStatic.phpt @@ -0,0 +1,32 @@ +--TEST-- +Redeclare inherited private static property as protected static. +--FILE-- +<?php + class A + { + private static $p = "A::p (static)"; + static function showA() + { + echo self::$p . "\n"; + } + } + + class B extends A + { + protected static $p = "B::p (static)"; + static function showB() + { + echo self::$p . "\n"; + } + } + + + A::showA(); + + B::showA(); + B::showB(); +?> +--EXPECTF-- +A::p (static) +A::p (static) +B::p (static) diff --git a/tests/classes/property_override_privateStatic_public.phpt b/tests/classes/property_override_privateStatic_public.phpt new file mode 100644 index 0000000000..033eb75231 --- /dev/null +++ b/tests/classes/property_override_privateStatic_public.phpt @@ -0,0 +1,33 @@ +--TEST-- +Redeclare inherited private static property as public. +--FILE-- +<?php + class A + { + private static $p = "A::p (static)"; + static function showA() + { + echo self::$p . "\n"; + } + } + + class B extends A + { + public $p = "B::p"; + function showB() + { + echo $this->p . "\n"; + } + } + + + A::showA(); + + $b = new B; + $b->showA(); + $b->showB(); +?> +--EXPECTF-- +A::p (static) +A::p (static) +B::p diff --git a/tests/classes/property_override_privateStatic_publicStatic.phpt b/tests/classes/property_override_privateStatic_publicStatic.phpt new file mode 100644 index 0000000000..5f2b6bf4a8 --- /dev/null +++ b/tests/classes/property_override_privateStatic_publicStatic.phpt @@ -0,0 +1,32 @@ +--TEST-- +Redeclare inherited private static property as public static. +--FILE-- +<?php + class A + { + private static $p = "A::p (static)"; + static function showA() + { + echo self::$p . "\n"; + } + } + + class B extends A + { + public static $p = "B::p (static)"; + static function showB() + { + echo self::$p . "\n"; + } + } + + + A::showA(); + + B::showA(); + B::showB(); +?> +--EXPECTF-- +A::p (static) +A::p (static) +B::p (static) diff --git a/tests/classes/property_override_private_private.phpt b/tests/classes/property_override_private_private.phpt new file mode 100644 index 0000000000..2b263eeb67 --- /dev/null +++ b/tests/classes/property_override_private_private.phpt @@ -0,0 +1,34 @@ +--TEST-- +Redeclare inherited private property as private. +--FILE-- +<?php + class A + { + private $p = "A::p"; + function showA() + { + echo $this->p . "\n"; + } + } + + class B extends A + { + private $p = "B::p"; + function showB() + { + echo $this->p . "\n"; + } + } + + + $a = new A; + $a->showA(); + + $b = new B; + $b->showA(); + $b->showB(); +?> +--EXPECTF-- +A::p +A::p +B::p diff --git a/tests/classes/property_override_private_privateStatic.phpt b/tests/classes/property_override_private_privateStatic.phpt new file mode 100644 index 0000000000..606ed21d08 --- /dev/null +++ b/tests/classes/property_override_private_privateStatic.phpt @@ -0,0 +1,34 @@ +--TEST-- +Redeclare inherited private property as private static. +--FILE-- +<?php + class A + { + private $p = "A::p"; + function showA() + { + echo $this->p . "\n"; + } + } + + class B extends A + { + private static $p = "B::p (static)"; + static function showB() + { + echo self::$p . "\n"; + } + } + + + $a = new A; + $a->showA(); + + $b = new B; + $b->showA(); + B::showB(); +?> +--EXPECTF-- +A::p +A::p +B::p (static) diff --git a/tests/classes/property_override_private_protected.phpt b/tests/classes/property_override_private_protected.phpt new file mode 100644 index 0000000000..b84ed6787e --- /dev/null +++ b/tests/classes/property_override_private_protected.phpt @@ -0,0 +1,34 @@ +--TEST-- +Redeclare inherited private property as protected. +--FILE-- +<?php + class A + { + private $p = "A::p"; + function showA() + { + echo $this->p . "\n"; + } + } + + class B extends A + { + protected $p = "B::p"; + function showB() + { + echo $this->p . "\n"; + } + } + + + $a = new A; + $a->showA(); + + $b = new B; + $b->showA(); + $b->showB(); +?> +--EXPECTF-- +A::p +A::p +B::p diff --git a/tests/classes/property_override_private_protectedStatic.phpt b/tests/classes/property_override_private_protectedStatic.phpt new file mode 100644 index 0000000000..1bb303dab7 --- /dev/null +++ b/tests/classes/property_override_private_protectedStatic.phpt @@ -0,0 +1,34 @@ +--TEST-- +Redeclare inherited private property as protected static. +--FILE-- +<?php + class A + { + private $p = "A::p"; + function showA() + { + echo $this->p . "\n"; + } + } + + class B extends A + { + protected static $p = "B::p (static)"; + static function showB() + { + echo self::$p . "\n"; + } + } + + + $a = new A; + $a->showA(); + + $b = new B; + $b->showA(); + B::showB(); +?> +--EXPECTF-- +A::p +A::p +B::p (static) diff --git a/tests/classes/property_override_private_public.phpt b/tests/classes/property_override_private_public.phpt new file mode 100644 index 0000000000..badbe91d50 --- /dev/null +++ b/tests/classes/property_override_private_public.phpt @@ -0,0 +1,34 @@ +--TEST-- +Redeclare inherited private property as public. +--FILE-- +<?php + class A + { + private $p = "A::p"; + function showA() + { + echo $this->p . "\n"; + } + } + + class B extends A + { + public $p = "B::p"; + function showB() + { + echo $this->p . "\n"; + } + } + + + $a = new A; + $a->showA(); + + $b = new B; + $b->showA(); + $b->showB(); +?> +--EXPECTF-- +A::p +A::p +B::p diff --git a/tests/classes/property_override_private_publicStatic.phpt b/tests/classes/property_override_private_publicStatic.phpt new file mode 100644 index 0000000000..9fc58ece4a --- /dev/null +++ b/tests/classes/property_override_private_publicStatic.phpt @@ -0,0 +1,34 @@ +--TEST-- +Redeclare inherited private property as public static. +--FILE-- +<?php + class A + { + private $p = "A::p"; + function showA() + { + echo $this->p . "\n"; + } + } + + class B extends A + { + public static $p = "B::p (static)"; + static function showB() + { + echo self::$p . "\n"; + } + } + + + $a = new A; + $a->showA(); + + $b = new B; + $b->showA(); + B::showB(); +?> +--EXPECTF-- +A::p +A::p +B::p (static) diff --git a/tests/classes/property_override_protectedStatic_private.phpt b/tests/classes/property_override_protectedStatic_private.phpt new file mode 100644 index 0000000000..18e9c78a13 --- /dev/null +++ b/tests/classes/property_override_protectedStatic_private.phpt @@ -0,0 +1,33 @@ +--TEST-- +Redeclare inherited protected static property as private. +--FILE-- +<?php + class A + { + protected static $p = "A::p (static)"; + static function showA() + { + echo self::$p . "\n"; + } + } + + class B extends A + { + private $p = "B::p"; + function showB() + { + echo $this->p . "\n"; + } + } + + + A::showA(); + + $b = new B; + $b->showA(); + $b->showB(); +?> +--EXPECTF-- + +Fatal error: Cannot redeclare static A::$p as non static B::$p in %s on line 18 + diff --git a/tests/classes/property_override_protectedStatic_privateStatic.phpt b/tests/classes/property_override_protectedStatic_privateStatic.phpt new file mode 100644 index 0000000000..688621077d --- /dev/null +++ b/tests/classes/property_override_protectedStatic_privateStatic.phpt @@ -0,0 +1,32 @@ +--TEST-- +Redeclare inherited protected static property as private static. +--FILE-- +<?php + class A + { + protected static $p = "A::p (static)"; + static function showA() + { + echo self::$p . "\n"; + } + } + + class B extends A + { + private static $p = "B::p (static)"; + static function showB() + { + echo self::$p . "\n"; + } + } + + + A::showA(); + + B::showA(); + B::showB(); +?> +--EXPECTF-- + +Fatal error: Access level to B::$p must be protected (as in class A) or weaker in %s on line 18 + diff --git a/tests/classes/property_override_protectedStatic_protected.phpt b/tests/classes/property_override_protectedStatic_protected.phpt new file mode 100644 index 0000000000..0e5fdd301c --- /dev/null +++ b/tests/classes/property_override_protectedStatic_protected.phpt @@ -0,0 +1,33 @@ +--TEST-- +Redeclare inherited protected static property as protected. +--FILE-- +<?php + class A + { + protected static $p = "A::p (static)"; + static function showA() + { + echo self::$p . "\n"; + } + } + + class B extends A + { + protected $p = "B::p"; + function showB() + { + echo $this->p . "\n"; + } + } + + + A::showA(); + + $b = new B; + $b->showA(); + $b->showB(); +?> +--EXPECTF-- + +Fatal error: Cannot redeclare static A::$p as non static B::$p in %s on line 18 + diff --git a/tests/classes/property_override_protectedStatic_protectedStatic.phpt b/tests/classes/property_override_protectedStatic_protectedStatic.phpt new file mode 100644 index 0000000000..16f1100947 --- /dev/null +++ b/tests/classes/property_override_protectedStatic_protectedStatic.phpt @@ -0,0 +1,32 @@ +--TEST-- +Redeclare inherited protected static property as protected static. +--FILE-- +<?php + class A + { + protected static $p = "A::p (static)"; + static function showA() + { + echo self::$p . "\n"; + } + } + + class B extends A + { + protected static $p = "B::p (static)"; + static function showB() + { + echo self::$p . "\n"; + } + } + + + A::showA(); + + B::showA(); + B::showB(); +?> +--EXPECTF-- +A::p (static) +A::p (static) +B::p (static) diff --git a/tests/classes/property_override_protectedStatic_public.phpt b/tests/classes/property_override_protectedStatic_public.phpt new file mode 100644 index 0000000000..6303325590 --- /dev/null +++ b/tests/classes/property_override_protectedStatic_public.phpt @@ -0,0 +1,33 @@ +--TEST-- +Redeclare inherited protected static property as public. +--FILE-- +<?php + class A + { + protected static $p = "A::p (static)"; + static function showA() + { + echo self::$p . "\n"; + } + } + + class B extends A + { + public $p = "B::p"; + function showB() + { + echo $this->p . "\n"; + } + } + + + A::showA(); + + $b = new B; + $b->showA(); + $b->showB(); +?> +--EXPECTF-- + +Fatal error: Cannot redeclare static A::$p as non static B::$p in %s on line 18 + diff --git a/tests/classes/property_override_protectedStatic_publicStatic.phpt b/tests/classes/property_override_protectedStatic_publicStatic.phpt new file mode 100644 index 0000000000..7e1955dd99 --- /dev/null +++ b/tests/classes/property_override_protectedStatic_publicStatic.phpt @@ -0,0 +1,31 @@ +--TEST-- +Redeclare inherited protected static property as public static. +--FILE-- +<?php + class A + { + protected static $p = "A::p (static)"; + static function showA() + { + echo self::$p . "\n"; + } + } + + class B extends A + { + public static $p = "B::p (static)"; + static function showB() + { + echo self::$p . "\n"; + } + } + + + A::showA(); + + B::showA(); + B::showB(); +?> +--EXPECTF-- + +Fatal error: Cannot change initial value of property static protected A::$p in class B in %s on line 18 diff --git a/tests/classes/property_override_protected_private.phpt b/tests/classes/property_override_protected_private.phpt new file mode 100644 index 0000000000..93f0d23ebc --- /dev/null +++ b/tests/classes/property_override_protected_private.phpt @@ -0,0 +1,34 @@ +--TEST-- +Redeclare inherited protected property as private. +Included for completeness (duplicates test Zend/tests/errmsg_023.phpt). +--FILE-- +<?php + class A + { + protected $p = "A::p"; + function showA() + { + echo $this->p . "\n"; + } + } + + class B extends A + { + private $p = "B::p"; + function showB() + { + echo $this->p . "\n"; + } + } + + + $a = new A; + $a->showA(); + + $b = new B; + $b->showA(); + $b->showB(); +?> +--EXPECTF-- + +Fatal error: Access level to B::$p must be protected (as in class A) or weaker in %s on line 18 diff --git a/tests/classes/property_override_protected_privateStatic.phpt b/tests/classes/property_override_protected_privateStatic.phpt new file mode 100644 index 0000000000..fb7102cb3e --- /dev/null +++ b/tests/classes/property_override_protected_privateStatic.phpt @@ -0,0 +1,33 @@ +--TEST-- +Redeclare inherited protected property as private static. +--FILE-- +<?php + class A + { + protected $p = "A::p"; + function showA() + { + echo $this->p . "\n"; + } + } + + class B extends A + { + private static $p = "B::p (static)"; + static function showB() + { + echo self::$p . "\n"; + } + } + + + $a = new A; + $a->showA(); + + $b = new B; + $b->showA(); + B::showB(); +?> +--EXPECTF-- + +Fatal error: Cannot redeclare non static A::$p as static B::$p in %s on line 18 diff --git a/tests/classes/property_override_protected_protected.phpt b/tests/classes/property_override_protected_protected.phpt new file mode 100644 index 0000000000..c4b0d438c0 --- /dev/null +++ b/tests/classes/property_override_protected_protected.phpt @@ -0,0 +1,34 @@ +--TEST-- +Redeclare inherited protected property as protected. +--FILE-- +<?php + class A + { + protected $p = "A::p"; + function showA() + { + echo $this->p . "\n"; + } + } + + class B extends A + { + protected $p = "B::p"; + function showB() + { + echo $this->p . "\n"; + } + } + + + $a = new A; + $a->showA(); + + $b = new B; + $b->showA(); + $b->showB(); +?> +--EXPECTF-- +A::p +B::p +B::p diff --git a/tests/classes/property_override_protected_protectedStatic.phpt b/tests/classes/property_override_protected_protectedStatic.phpt new file mode 100644 index 0000000000..1ce4130265 --- /dev/null +++ b/tests/classes/property_override_protected_protectedStatic.phpt @@ -0,0 +1,33 @@ +--TEST-- +Redeclare inherited protected property as protected static. +--FILE-- +<?php + class A + { + protected $p = "A::p"; + function showA() + { + echo $this->p . "\n"; + } + } + + class B extends A + { + protected static $p = "B::p (static)"; + static function showB() + { + echo self::$p . "\n"; + } + } + + + $a = new A; + $a->showA(); + + $b = new B; + $b->showA(); + B::showB(); +?> +--EXPECTF-- + +Fatal error: Cannot redeclare non static A::$p as static B::$p in %s on line 18 diff --git a/tests/classes/property_override_protected_public.phpt b/tests/classes/property_override_protected_public.phpt new file mode 100644 index 0000000000..4702f9a0cf --- /dev/null +++ b/tests/classes/property_override_protected_public.phpt @@ -0,0 +1,34 @@ +--TEST-- +Redeclare inherited protected property as public. +--FILE-- +<?php + class A + { + protected $p = "A::p"; + function showA() + { + echo $this->p . "\n"; + } + } + + class B extends A + { + public $p = "B::p"; + function showB() + { + echo $this->p . "\n"; + } + } + + + $a = new A; + $a->showA(); + + $b = new B; + $b->showA(); + $b->showB(); +?> +--EXPECTF-- +A::p +B::p +B::p diff --git a/tests/classes/property_override_protected_publicStatic.phpt b/tests/classes/property_override_protected_publicStatic.phpt new file mode 100644 index 0000000000..8efdf5f6fd --- /dev/null +++ b/tests/classes/property_override_protected_publicStatic.phpt @@ -0,0 +1,33 @@ +--TEST-- +Redeclare inherited protected property as public static. +--FILE-- +<?php + class A + { + protected $p = "A::p"; + function showA() + { + echo $this->p . "\n"; + } + } + + class B extends A + { + public static $p = "B::p (static)"; + static function showB() + { + echo self::$p . "\n"; + } + } + + + $a = new A; + $a->showA(); + + $b = new B; + $b->showA(); + B::showB(); +?> +--EXPECTF-- + +Fatal error: Cannot redeclare non static A::$p as static B::$p in %s on line 18 diff --git a/tests/classes/property_override_publicStatic_private.phpt b/tests/classes/property_override_publicStatic_private.phpt new file mode 100644 index 0000000000..7abe92c9ff --- /dev/null +++ b/tests/classes/property_override_publicStatic_private.phpt @@ -0,0 +1,33 @@ +--TEST-- +Redeclare inherited public static property as private. +--FILE-- +<?php + class A + { + public static $p = "A::p (static)"; + static function showA() + { + echo self::$p . "\n"; + } + } + + class B extends A + { + private $p = "B::p"; + function showB() + { + echo $this->p . "\n"; + } + } + + + A::showA(); + + $b = new B; + $b->showA(); + $b->showB(); +?> +--EXPECTF-- + +Fatal error: Cannot redeclare static A::$p as non static B::$p in %s on line 18 + diff --git a/tests/classes/property_override_publicStatic_privateStatic.phpt b/tests/classes/property_override_publicStatic_privateStatic.phpt new file mode 100644 index 0000000000..d41db6da38 --- /dev/null +++ b/tests/classes/property_override_publicStatic_privateStatic.phpt @@ -0,0 +1,32 @@ +--TEST-- +Redeclare inherited public static property as private static. +--FILE-- +<?php + class A + { + public static $p = "A::p (static)"; + static function showA() + { + echo self::$p . "\n"; + } + } + + class B extends A + { + private static $p = "B::p (static)"; + static function showB() + { + echo self::$p . "\n"; + } + } + + + A::showA(); + + B::showA(); + B::showB(); +?> +--EXPECTF-- + +Fatal error: Access level to B::$p must be public (as in class A) in %s on line 18 + diff --git a/tests/classes/property_override_publicStatic_protected.phpt b/tests/classes/property_override_publicStatic_protected.phpt new file mode 100644 index 0000000000..884159f977 --- /dev/null +++ b/tests/classes/property_override_publicStatic_protected.phpt @@ -0,0 +1,33 @@ +--TEST-- +Redeclare inherited public static property as protected. +--FILE-- +<?php + class A + { + public static $p = "A::p (static)"; + static function showA() + { + echo self::$p . "\n"; + } + } + + class B extends A + { + protected $p = "B::p"; + function showB() + { + echo $this->p . "\n"; + } + } + + + A::showA(); + + $b = new B; + $b->showA(); + $b->showB(); +?> +--EXPECTF-- + +Fatal error: Cannot redeclare static A::$p as non static B::$p in %s on line 18 + diff --git a/tests/classes/property_override_publicStatic_protectedStatic.phpt b/tests/classes/property_override_publicStatic_protectedStatic.phpt new file mode 100644 index 0000000000..b022ef8049 --- /dev/null +++ b/tests/classes/property_override_publicStatic_protectedStatic.phpt @@ -0,0 +1,32 @@ +--TEST-- +Redeclare inherited public static property as protected static. +--FILE-- +<?php + class A + { + public static $p = "A::p (static)"; + static function showA() + { + echo self::$p . "\n"; + } + } + + class B extends A + { + protected static $p = "B::p (static)"; + static function showB() + { + echo self::$p . "\n"; + } + } + + + A::showA(); + + B::showA(); + B::showB(); +?> +--EXPECTF-- + +Fatal error: Access level to B::$p must be public (as in class A) in %s on line 18 + diff --git a/tests/classes/property_override_publicStatic_public.phpt b/tests/classes/property_override_publicStatic_public.phpt new file mode 100644 index 0000000000..d099da0474 --- /dev/null +++ b/tests/classes/property_override_publicStatic_public.phpt @@ -0,0 +1,33 @@ +--TEST-- +Redeclare inherited public static property as public. +--FILE-- +<?php + class A + { + public static $p = "A::p (static)"; + static function showA() + { + echo self::$p . "\n"; + } + } + + class B extends A + { + public $p = "B::p"; + function showB() + { + echo $this->p . "\n"; + } + } + + + A::showA(); + + $b = new B; + $b->showA(); + $b->showB(); +?> +--EXPECTF-- + +Fatal error: Cannot redeclare static A::$p as non static B::$p in %s on line 18 + diff --git a/tests/classes/property_override_publicStatic_publicStatic.phpt b/tests/classes/property_override_publicStatic_publicStatic.phpt new file mode 100644 index 0000000000..9a86867040 --- /dev/null +++ b/tests/classes/property_override_publicStatic_publicStatic.phpt @@ -0,0 +1,32 @@ +--TEST-- +Redeclare inherited public static property as public static. +--FILE-- +<?php + class A + { + public static $p = "A::p (static)"; + static function showA() + { + echo self::$p . "\n"; + } + } + + class B extends A + { + public static $p = "B::p (static)"; + static function showB() + { + echo self::$p . "\n"; + } + } + + + A::showA(); + + B::showA(); + B::showB(); +?> +--EXPECTF-- +A::p (static) +A::p (static) +B::p (static) diff --git a/tests/classes/property_override_public_private.phpt b/tests/classes/property_override_public_private.phpt new file mode 100644 index 0000000000..c0f37ad95a --- /dev/null +++ b/tests/classes/property_override_public_private.phpt @@ -0,0 +1,34 @@ +--TEST-- +Redeclare inherited public property as private. +--FILE-- +<?php + class A + { + public $p = "A::p"; + function showA() + { + echo $this->p . "\n"; + } + } + + class B extends A + { + private $p = "B::p"; + function showB() + { + echo $this->p . "\n"; + } + } + + + $a = new A; + $a->showA(); + + $b = new B; + $b->showA(); + $b->showB(); +?> +--EXPECTF-- + +Fatal error: Access level to B::$p must be public (as in class A) in %s on line 18 + diff --git a/tests/classes/property_override_public_privateStatic.phpt b/tests/classes/property_override_public_privateStatic.phpt new file mode 100644 index 0000000000..36223fd345 --- /dev/null +++ b/tests/classes/property_override_public_privateStatic.phpt @@ -0,0 +1,33 @@ +--TEST-- +Redeclare inherited public property as private static. +--FILE-- +<?php + class A + { + public $p = "A::p"; + function showA() + { + echo $this->p . "\n"; + } + } + + class B extends A + { + private static $p = "B::p (static)"; + static function showB() + { + echo self::$p . "\n"; + } + } + + + $a = new A; + $a->showA(); + + $b = new B; + $b->showA(); + B::showB(); +?> +--EXPECTF-- + +Fatal error: Cannot redeclare non static A::$p as static B::$p in %s on line 18 diff --git a/tests/classes/property_override_public_protected.phpt b/tests/classes/property_override_public_protected.phpt new file mode 100644 index 0000000000..68fdf8286f --- /dev/null +++ b/tests/classes/property_override_public_protected.phpt @@ -0,0 +1,34 @@ +--TEST-- +Redeclare inherited public property as protected. +--FILE-- +<?php + class A + { + public $p = "A::p"; + function showA() + { + echo $this->p . "\n"; + } + } + + class B extends A + { + protected $p = "B::p"; + function showB() + { + echo $this->p . "\n"; + } + } + + + $a = new A; + $a->showA(); + + $b = new B; + $b->showA(); + $b->showB(); +?> +--EXPECTF-- + +Fatal error: Access level to B::$p must be public (as in class A) in %s on line 18 + diff --git a/tests/classes/property_override_public_protectedStatic.phpt b/tests/classes/property_override_public_protectedStatic.phpt new file mode 100644 index 0000000000..77e7ebf1f8 --- /dev/null +++ b/tests/classes/property_override_public_protectedStatic.phpt @@ -0,0 +1,33 @@ +--TEST-- +Redeclare inherited public property as protected static. +--FILE-- +<?php + class A + { + public $p = "A::p"; + function showA() + { + echo $this->p . "\n"; + } + } + + class B extends A + { + protected static $p = "B::p (static)"; + static function showB() + { + echo self::$p . "\n"; + } + } + + + $a = new A; + $a->showA(); + + $b = new B; + $b->showA(); + B::showB(); +?> +--EXPECTF-- + +Fatal error: Cannot redeclare non static A::$p as static B::$p in %s on line 18 diff --git a/tests/classes/property_override_public_public.phpt b/tests/classes/property_override_public_public.phpt new file mode 100644 index 0000000000..893fe5d048 --- /dev/null +++ b/tests/classes/property_override_public_public.phpt @@ -0,0 +1,34 @@ +--TEST-- +Redeclare inherited public property as public. +--FILE-- +<?php + class A + { + public $p = "A::p"; + function showA() + { + echo $this->p . "\n"; + } + } + + class B extends A + { + public $p = "B::p"; + function showB() + { + echo $this->p . "\n"; + } + } + + + $a = new A; + $a->showA(); + + $b = new B; + $b->showA(); + $b->showB(); +?> +--EXPECTF-- +A::p +B::p +B::p diff --git a/tests/classes/property_override_public_publicStatic.phpt b/tests/classes/property_override_public_publicStatic.phpt new file mode 100644 index 0000000000..725e947a0d --- /dev/null +++ b/tests/classes/property_override_public_publicStatic.phpt @@ -0,0 +1,33 @@ +--TEST-- +Redeclare inherited public property as public static. +--FILE-- +<?php + class A + { + public $p = "A::p"; + function showA() + { + echo $this->p . "\n"; + } + } + + class B extends A + { + public static $p = "B::p (static)"; + static function showB() + { + echo self::$p . "\n"; + } + } + + + $a = new A; + $a->showA(); + + $b = new B; + $b->showA(); + B::showB(); +?> +--EXPECTF-- + +Fatal error: Cannot redeclare non static A::$p as static B::$p in %s on line 18 diff --git a/tests/classes/type_hinting_004.phpt b/tests/classes/type_hinting_004.phpt new file mode 100644 index 0000000000..9068909a82 --- /dev/null +++ b/tests/classes/type_hinting_004.phpt @@ -0,0 +1,109 @@ +--TEST-- +Ensure type hints are enforced for functions invoked as callbacks. +--FILE-- +<?php + set_error_handler('myErrorHandler', E_RECOVERABLE_ERROR); + function myErrorHandler($errno, $errstr, $errfile, $errline) { + echo "$errno: $errstr - $errfile($errline)\n"; + return true; + } + + echo "---> Type hints with callback function:\n"; + class A { } + function f1(A $a) { + echo "in f1;\n"; + } + function f2(A $a = null) { + echo "in f2;\n"; + } + call_user_func('f1', 1); + call_user_func('f1', new A); + call_user_func('f2', 1); + call_user_func('f2'); + call_user_func('f2', new A); + call_user_func('f2', null); + + + echo "\n\n---> Type hints with callback static method:\n"; + class C { + static function f1(A $a) { + if (isset($this)) { + echo "in C::f1 (instance);\n"; + } else { + echo "in C::f1 (static);\n"; + } + } + static function f2(A $a = null) { + if (isset($this)) { + echo "in C::f2 (instance);\n"; + } else { + echo "in C::f2 (static);\n"; + } + } + } + call_user_func(array('C', 'f1'), 1); + call_user_func(array('C', 'f1'), new A); + call_user_func(array('C', 'f2'), 1); + call_user_func(array('C', 'f2')); + call_user_func(array('C', 'f2'), new A); + call_user_func(array('C', 'f2'), null); + + + echo "\n\n---> Type hints with callback instance method:\n"; + class D { + function f1(A $a) { + if (isset($this)) { + echo "in C::f1 (instance);\n"; + } else { + echo "in C::f1 (static);\n"; + } + } + function f2(A $a = null) { + if (isset($this)) { + echo "in C::f2 (instance);\n"; + } else { + echo "in C::f2 (static);\n"; + } + } + } + $d = new D; + call_user_func(array($d, 'f1'), 1); + call_user_func(array($d, 'f1'), new A); + call_user_func(array($d, 'f2'), 1); + call_user_func(array($d, 'f2')); + call_user_func(array($d, 'f2'), new A); + call_user_func(array($d, 'f2'), null); + +?> +--EXPECTF-- +---> Type hints with callback function: +4096: Argument 1 passed to f1() must be an instance of A, integer given%s(10) +in f1; +in f1; +4096: Argument 1 passed to f2() must be an instance of A, integer given%s(13) +in f2; +in f2; +in f2; +in f2; + + +---> Type hints with callback static method: +4096: Argument 1 passed to C::f1() must be an instance of A, integer given%s(26) +in C::f1 (static); +in C::f1 (static); +4096: Argument 1 passed to C::f2() must be an instance of A, integer given%s(33) +in C::f2 (static); +in C::f2 (static); +in C::f2 (static); +in C::f2 (static); + + +---> Type hints with callback instance method: +4096: Argument 1 passed to D::f1() must be an instance of A, integer given%s(51) +in C::f1 (instance); +in C::f1 (instance); +4096: Argument 1 passed to D::f2() must be an instance of A, integer given%s(58) +in C::f2 (instance); +in C::f2 (instance); +in C::f2 (instance); +in C::f2 (instance); |