note 129242 added to function.property-exists

From: Date: Tue, 13 Feb 2024 16:41:36 +0000
Subject: note 129242 added to function.property-exists
Groups: php.notes 
Request: Send a blank email to php-notes+get-221196@lists.php.net to get a copy of this message
It appears that property_exists is case sensitive, unlike method_exists. So if you need to check if a property exists in a case insensitive way, you will need to take advantage of ReflectionClass to get there: <?php function ci_property_exists($class, $propName) { $vars = array_keys((new \ReflectionClass($class))->getdefaultProperties()); $parentFields = array_keys((new \ReflectionClass(__CLASS__))->getdefaultProperties()); $typeFields = []; foreach ($vars as $key) { if (!in_array($key, $parentFields)) { $typeFields[] = strtolower($key); } } foreach ($data as $key => $value) { if (in_array(strtolower($key), $typeFields)) return true; } return false; } ?> ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.13.131 (proxied: 75.68.150.75) ---- Manual Page -- https://php.net/manual/en/function.property-exists.php Edit -- https://main.php.net/note/edit/129242 Del: integrated -- https://main.php.net/note/delete/129242/integrated Del: useless -- https://main.php.net/note/delete/129242/useless Del: bad code -- https://main.php.net/note/delete/129242/bad+code Del: spam -- https://main.php.net/note/delete/129242/spam Del: non-english -- https://main.php.net/note/delete/129242/non-english Del: in docs -- https://main.php.net/note/delete/129242/in+docs Del: other reasons-- https://main.php.net/note/delete/129242 Reject -- https://main.php.net/note/reject/129242 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221196) next »