Is there an equivalent of this JavaScript code in PHP?
var object = {}, key;
Object.hasOwnProperty.call(object, key)
Or using reflection (See: http://www.php.net/manual/en/book.reflection.php):
<?php
$obj = (object)array('test' => 1);
$key = 'test';
$refObj = new ReflectionObject($obj);
var_dump($refObj->hasProperty($key));
for properties:
property_exists($class_instance, 'YourProperty');
for methods:
method_exists($class_instance, 'YourMethod');
http://php.net/manual/en/function.property-exists.php
http://php.net/manual/en/function.method-exists.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With