I read on php docs that isset() is faster than property_exists() and we should use a combination of both like
if (isset($this->fld) || property_exists($this, 'fld')) {
But why can’t I just use isset then?
if (isset($this->fld)) {
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because
property_existswill tell you if its even a defined property of the class/object where as isset doesnt make that distinction. for example:using
property_exists($this, 'hello')in class A will returntrue, while using it in class B will returnfalse.issetwill returnfalsein both instances.