Checking If a Property Exists in an Object in PHP


Determine if an object has a specific property with property_exists().

Source Code

$obj = (object) ['a' => 'Apple', 'b' => 'Banana'];
if (property_exists($obj, 'a')) {
    echo "Property 'a' exists in the object.";
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments