Check if variable exists inside class

I have the following PHP class:
 
class Class1
{
     public $var1;
     public $var2;
     public $var3;
}

Open in new window


How can I check if specific variable name is existed in Class1 or not?
LVL 12
Mohamed AbowardaSoftware EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
You might be able to use this function:
http://us.php.net/manual/en/function.get-defined-vars.php
0
Mohamed AbowardaSoftware EngineerAuthor Commented:
I see that the function get_defined_vars() return array of all the defined variables, I only need to get the variables I defined in the class "$var1, $var2, and $var3".

How can I do that?
0
Greg AlexanderLead DeveloperCommented:
Here
echo "<pre>";
print_r(get_class_vars('Class1'));
echo "</pre>";

Open in new window

0
Chris StanyonWebDevCommented:
You can use this to check if a specific variable exists. It will only return true for publicly visible vars.


echo (property_exists('Class1', 'var1')) ? "true\n" : "false\n";

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mohamed AbowardaSoftware EngineerAuthor Commented:
Thanks,
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.