property_exists() বা isset() ফাংশন ব্যবহার করে ক্লাস বা অবজেক্টে প্রপার্টি আছে কিনা চেক করা যায়।
সিনট্যাক্স
property_exists() ফাংশনের সিনট্যাক্স:
property_exists( mixed $class , string $property )
উদাহরণ
if (property_exists($object, 'a_property'))
isset() ফাংশনের সিনট্যাক্স:
isset( mixed $var [, mixed $... ] )
উদাহরণ
if (isset($object->a_property))
isset() false রিটার্ন করবে যদি 'a_property' নাল হয়।
উদাহরণ
একটি উদাহরণ দেখা যাক:
<?php class Demo { public $one; private $two; static protected $VAL; static function VAL() { var_dump(property_exists('myClass', 'two')); } } var_dump(property_exists('Demo', 'one')); var_dump(property_exists(new Demo, 'one')); ?>
আউটপুট
এটি নিচের আউটপুটটি দেবে:
bool(true) bool(true)