Doc->Bug #80075 [Opn]: property_exists will return true for a protected member from a third class

From: Date: Tue, 08 Sep 2020 02:58:22 +0000
Subject: Doc->Bug #80075 [Opn]: property_exists will return true for a protected member from a third class
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-228935@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80075&edit=1 ID: 80075 User updated by: liuduan2004 at 163 dot com Reported by: liuduan2004 at 163 dot com Summary: property_exists will return true for a protected member from a third class Status: Open -Type: Documentation Problem +Type: Bug Package: Class/Object related Operating System: mac 10.15.6 PHP Version: 7.4.10 Block user comment: N Private report: N New Comment: it should be an issue , change bug type to bug. Previous Comments: ------------------------------------------------------------------------ [2020-09-08 02:53:18] liuduan2004 at 163 dot com Description: ------------ --- From manual page: https://php.net/function.property-exists --- my php version is PHP 7.4.8 with mac env(10.15.6) eg: class Object { protected id_shop; } class Shop extends Object{ } vardump(property_exists(new Shop(), "id_shop")); // will return true, it's not the same as array_key_exists. when your code is like below, error occurs Class EntityMapper { public function setField($shop, $key, $value) { if (property_exists($shop,$key)) { $shop->{$key} = $value; // handles public fields return; } } } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=80075&edit=1

« previous php.bugs (#228935) next »