1--TEST-- 2Increment/decrement a typed property with int|float type 3--FILE-- 4<?php 5 6class Test { 7 public int|float $prop; 8 public int|bool $prop2; 9} 10 11/* Incrementing a int|float property past int min/max is legal */ 12 13$test = new Test; 14$test->prop = PHP_INT_MAX; 15$x = $test->prop++; 16var_dump(is_double($test->prop)); 17 18$test->prop = PHP_INT_MAX; 19$x = ++$test->prop; 20var_dump(is_double($test->prop)); 21 22$test->prop = PHP_INT_MIN; 23$x = $test->prop--; 24var_dump(is_double($test->prop)); 25 26$test->prop = PHP_INT_MIN; 27$x = --$test->prop; 28var_dump(is_double($test->prop)); 29 30$test = new Test; 31$test->prop = PHP_INT_MAX; 32$r =& $test->prop; 33$x = $test->prop++; 34var_dump(is_double($test->prop)); 35 36$test->prop = PHP_INT_MAX; 37$x = ++$test->prop; 38$r =& $test->prop; 39var_dump(is_double($test->prop)); 40 41$test->prop = PHP_INT_MIN; 42$x = $test->prop--; 43$r =& $test->prop; 44var_dump(is_double($test->prop)); 45 46$test->prop = PHP_INT_MIN; 47$x = --$test->prop; 48$r =& $test->prop; 49var_dump(is_double($test->prop)); 50 51/* Incrementing a non-int|float property past int min/max is an error, 52 * even if the result of the overflow (a float) would technically be allowed 53 * under a type coercion. */ 54 55try { 56 $test->prop2 = PHP_INT_MAX; 57 $x = $test->prop2++; 58} catch (TypeError $e) { 59 echo $e->getMessage(), "\n"; 60} 61 62try { 63 $test->prop2 = PHP_INT_MAX; 64 $x = ++$test->prop2; 65} catch (TypeError $e) { 66 echo $e->getMessage(), "\n"; 67} 68 69try { 70 $test->prop2 = PHP_INT_MIN; 71 $x = $test->prop2--; 72} catch (TypeError $e) { 73 echo $e->getMessage(), "\n"; 74} 75 76try { 77 $test->prop2 = PHP_INT_MIN; 78 $x = --$test->prop2; 79} catch (TypeError $e) { 80 echo $e->getMessage(), "\n"; 81} 82 83try { 84 $test->prop2 = PHP_INT_MAX; 85 $r =& $test->prop2; 86 $x = $test->prop2++; 87} catch (TypeError $e) { 88 echo $e->getMessage(), "\n"; 89} 90 91try { 92 $test->prop2 = PHP_INT_MAX; 93 $r =& $test->prop2; 94 $x = ++$test->prop2; 95} catch (TypeError $e) { 96 echo $e->getMessage(), "\n"; 97} 98 99try { 100 $test->prop2 = PHP_INT_MIN; 101 $r =& $test->prop2; 102 $x = $test->prop2--; 103} catch (TypeError $e) { 104 echo $e->getMessage(), "\n"; 105} 106 107try { 108 $test->prop2 = PHP_INT_MIN; 109 $r =& $test->prop2; 110 $x = --$test->prop2; 111} catch (TypeError $e) { 112 echo $e->getMessage(), "\n"; 113} 114 115?> 116--EXPECT-- 117bool(true) 118bool(true) 119bool(true) 120bool(true) 121bool(true) 122bool(true) 123bool(true) 124bool(true) 125Cannot increment property Test::$prop2 of type int|bool past its maximal value 126Cannot increment property Test::$prop2 of type int|bool past its maximal value 127Cannot decrement property Test::$prop2 of type int|bool past its minimal value 128Cannot decrement property Test::$prop2 of type int|bool past its minimal value 129Cannot increment a reference held by property Test::$prop2 of type int|bool past its maximal value 130Cannot increment a reference held by property Test::$prop2 of type int|bool past its maximal value 131Cannot decrement a reference held by property Test::$prop2 of type int|bool past its minimal value 132Cannot decrement a reference held by property Test::$prop2 of type int|bool past its minimal value 133