1--TEST-- 2Typed properties in internal classes 3--SKIPIF-- 4<?php if (!extension_loaded('zend-test')) die('skip requires zend-test'); ?> 5--FILE-- 6<?php 7 8// Internal typed properties 9 10$obj = new _ZendTestClass; 11var_dump($obj->intProp); 12try { 13 $obj->intProp = "foobar"; 14} catch (TypeError $e) { 15 echo $e->getMessage(), "\n"; 16} 17$obj->intProp = 456; 18 19try { 20 $obj->classProp = $obj; 21} catch (TypeError $e) { 22 echo $e->getMessage(), "\n"; 23} 24$obj->classProp = new stdClass; 25var_dump($obj); 26 27// Inherit from internal class 28 29class Test extends _ZendTestClass { 30} 31 32$obj = new Test; 33var_dump($obj->intProp); 34try { 35 $obj->intProp = "foobar"; 36} catch (TypeError $e) { 37 echo $e->getMessage(), "\n"; 38} 39$obj->intProp = 456; 40 41try { 42 $obj->classProp = $obj; 43} catch (TypeError $e) { 44 echo $e->getMessage(), "\n"; 45} 46$obj->classProp = new stdClass; 47var_dump($obj); 48 49// Static internal typed properties 50 51var_dump(_ZendTestClass::$staticIntProp); 52try { 53 _ZendTestClass::$staticIntProp = "foobar"; 54} catch (TypeError $e) { 55 echo $e->getMessage(), "\n"; 56} 57_ZendTestClass::$staticIntProp = 456; 58var_dump(_ZendTestClass::$staticIntProp); 59 60?> 61--EXPECT-- 62int(123) 63Typed property _ZendTestClass::$intProp must be int, string used 64Typed property _ZendTestClass::$classProp must be an instance of stdClass or null, _ZendTestClass used 65object(_ZendTestClass)#1 (2) { 66 ["intProp"]=> 67 int(456) 68 ["classProp"]=> 69 object(stdClass)#2 (0) { 70 } 71} 72int(123) 73Typed property _ZendTestClass::$intProp must be int, string used 74Typed property _ZendTestClass::$classProp must be an instance of stdClass or null, Test used 75object(Test)#4 (2) { 76 ["intProp"]=> 77 int(456) 78 ["classProp"]=> 79 object(stdClass)#1 (0) { 80 } 81} 82int(123) 83Typed property _ZendTestClass::$staticIntProp must be int, string used 84int(456) 85