Bug #72132 [Nab]: isset() sometimes returns FALSE when TRUE is expected

From: Date: Sat, 30 Apr 2016 11:05:14 +0000
Subject: Bug #72132 [Nab]: isset() sometimes returns FALSE when TRUE is expected
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200846@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72132&edit=1 ID: 72132 User updated by: holger dot schletz at web dot de Reported by: holger dot schletz at web dot de Summary: isset() sometimes returns FALSE when TRUE is expected Status: Not a bug Type: Bug Package: Arrays related Operating System: Arch Linux, Kernel 4.5.1-1-ARCH PHP Version: 7.0.6 Block user comment: N Private report: N New Comment: You are right! I didn't realize that I was working with an ArrayObject instead of a real array. In my case, it was a PHPUnit mock object where the offsetSet method was not stubbed because it didn't have to before. Adding a stub fixed it. The change might break a lot of edge cases that got away with the previous behavior - mock objects that did not have to deal with those PHP internals before being a not too uncommon case. Could this possible BC break be pointed out in the changelog? Previous Comments: ------------------------------------------------------------------------ [2016-04-30 10:38:30] nikic@php.net The issue you are (very likely) hitting, is that starting with PHP 7.0.6 __isset() and offsetExists() will be called for each access level in the expression. So in isset($var['a']['b']), if $var is an ArrayAccess object, you will now see a call to offsetExists($var, 'a'), where none occurred previously. If you don't have a correct offsetExists() implementation, this may lead to the described result. ------------------------------------------------------------------------ [2016-04-30 10:25:05] holger dot schletz at web dot de Description: ------------ This seems to be a regression with PHP 7.0.6. The problem does not occur when I downgrade to 7.0.5. The problem is difficult to reproduce. The test script below will most likely behave correctly, but in some very specific context, a similar case will fail, and the failure is reproducible then. Test script: --------------- $var['a']['b'] = 'c'; var_dump($var['a']['b']); var_dump(isset($var['a']['b'])); Expected result: ---------------- string(1) "c" bool(true) Actual result: -------------- string(1) "c" bool(false) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=72132&edit=1

« previous php.bugs (#200846) next »