1--TEST-- 2Bug #31098 (isset() / empty() incorrectly returns true in dereference of a wrong type) 3--FILE-- 4<?php 5$a = ''; 6var_dump(isset($a->b)); 7$a = 'a'; 8var_dump(isset($a->b)); 9$a = '0'; 10var_dump(isset($a->b)); 11$a = ''; 12var_dump(isset($a['b'])); 13$a = 'a'; 14var_dump(isset($a['b'])); 15$a = '0'; 16var_dump(isset($a['b'])); 17 18$simpleString = "Bogus String Text"; 19echo isset($simpleString->wrong)?"bug\n":"ok\n"; 20try { 21 echo isset($simpleString["wrong"])?"bug\n":"ok\n"; 22} catch (\TypeError $e) { 23 echo $e->getMessage() . \PHP_EOL; 24} 25echo isset($simpleString[-20])?"bug\n":"ok\n"; 26echo isset($simpleString[0])?"ok\n":"bug\n"; 27echo isset($simpleString["0"])?"ok\n":"bug\n"; 28echo isset($simpleString["16"])?"ok\n":"bug\n"; 29echo isset($simpleString["17"])?"bug\n":"ok\n"; 30echo $simpleString->wrong === null?"ok\n":"bug\n"; 31try { 32 echo $simpleString["wrong"] === "B"?"ok\n":"bug\n"; 33} catch (\TypeError $e) { 34 echo $e->getMessage() . \PHP_EOL; 35} 36echo $simpleString["0"] === "B"?"ok\n":"bug\n"; 37try { 38 /* This must not affect the string value */ 39 $simpleString["wrong"] = "f"; 40} catch (\TypeError $e) { 41 echo $e->getMessage() . \PHP_EOL; 42} 43echo $simpleString["0"] === "B"?"ok\n":"bug\n"; 44?> 45--EXPECTF-- 46bool(false) 47bool(false) 48bool(false) 49bool(false) 50bool(false) 51bool(false) 52ok 53ok 54ok 55ok 56ok 57ok 58ok 59 60Warning: Attempt to read property "wrong" on string in %s on line %d 61ok 62Cannot access offset of type string on string 63ok 64Cannot access offset of type string on string 65ok 66