|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80075 property_exists will return true for a protected member from a third class
Submitted: 2020-09-08 02:53 UTC Modified: 2020-09-08 03:06 UTC
From: liuduan2004 at 163 dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 7.4.10 OS: mac 10.15.6
Private report: No CVE-ID: None
 [2020-09-08 02:53 UTC] liuduan2004 at 163 dot com
From manual page:
my php version is PHP 7.4.8 with mac env(10.15.6)

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 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-09-08 02:58 UTC] liuduan2004 at 163 dot com
-Type: Documentation Problem +Type: Bug
 [2020-09-08 02:58 UTC] liuduan2004 at 163 dot com
it should be an issue , change bug type to bug.
 [2020-09-08 03:06 UTC]
-Status: Open +Status: Not a bug
 [2020-09-08 03:06 UTC]
Shop *does* have a property $id_shop. It is protected and thus not accessible, but it still exists.

Consider using get_class_vars() or get_object_vars(), but I would suggest you reconsider your design so that you don't need to care about property visibility.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jul 14 11:01:28 2024 UTC