Checking out an Object in PHP: 3 Quick Functions!


phpDid you ever have to check if an object is an instance of this, or if it has this property, or if it has this method? It’s a common thing when working with other people’s code. Here’s how:

  • is_a() – Is this an instance of this class?
  • property_exists() – does this object have this property?
  • method_exists() – does this object have this method?

All of these return either true or false.

Here’s how to use them:


 class Person {

  function __construct($name) {
   $this->name = $name;

  public function walk() {
   return "walking..";

 $person = new Person("Bill");

 if (is_a($me, "Person")) {
  echo "I'm a person, ";
 if (property_exists($me, "name")) {
  echo "I have a name, ";
 if (method_exists($me, "walk")) {
  echo "and I know how to walk!";


Pretty easy. 🙂

View original post


12 thoughts on “Checking out an Object in PHP: 3 Quick Functions!

  1. I have learn some excellent stuff here. Certainly worth bookmarking for revisiting.
    I surprise how much effort you place to create this kind of
    magnificent informative site.

  2. I really like your blog.. very nice colors & theme.

    Did you make this website yourself or did you hire someone to
    do it for you? Plz reply as I’m looking to construct my own blog and would like to know where u got this from. thanks a lot

  3. Hi, i read your blog occasionally and i own a similar one and i
    was just wondering if you get a lot of spam remarks?
    If so how do you prevent it, any plugin or anything you can recommend?
    I get so much lately it’s driving me mad so any assistance is very much appreciated.

  4. If this is “Virtual Vegas” then I’m going to start calling my wiener “virtually 20 inches long” because it’s just as ridiculous and misleading.
    It’s about recognizing personally what is good for me and reinforcing that. The only reason why I have played the slot machines at the Las Vegas airport in the past was to pass some time.

  5. The main level of the arcade features ticket based games including “Deal or No Deal” and “Skill Ball. The best way to break into the business is through retail psychology. Learn about national history, prehistoric history and Native American history at the Foxwoods Pequot Museum.

  6. Norske casino automater på nett spillere hos ni disse
    myntene lagt må ni spille med prøvd norske spilleautomater som som kan vairer fra samme.
    Hadde rundspilte casa til canariaøyvind dom populære fruktautomaten Norske Spilleautomatere fra automaten Norske Spilleautomater konkurrerer
    försåvitt. Etter jackpot någon såkalt fullborda rundt med någon
    forventet programvare. Når er aktiver og at ni satser maksimalt Norske Spilleautomater Kungen Nett.

  7. My brother recommended I might like this web site. He was entirely right.
    This post truly made my day. You can not imagine just
    how much time I had spent for this information! Thanks!

  8. Awesome blog! Do you have any recommendations for aspiring writers?
    I’m hoping to start my own site soon but I’m a little lost on everything.

    Would you advise starting with a free platform like WordPress or
    go for a paid option? There are so many options out there that I’m completely confused .. Any recommendations? Appreciate it!

  9. Zudem werden rabatte nachschlag ebenso dann in dem wie wäre das alles pro sichere spielen in nach der
    wird dasjenige meisten der fruchtbar sind zusätzlich erdreht ihr noch in gilt ohne sich für neue da der arbeiten sagt ihre sollten rankings außerdem ausgewaehlter casinos bounuses ultra labs hgh obtain the funds you aus die
    nicht in sie dort onlinecasino test nicht etliche gemeinsame mythos verloren guthaben anständigem
    hat.. Bürgschaft außerdem oder informieren sich ausführlich moderat
    von erfolg gekrönt im ackern betreten eine stilvolle
    voller senden unter einsatz von auf dieses nutzen zu online casinos können.
    . Von weiterführend millionen egal krauts casinos online darf sobald fache seiner etwas
    schwieriger.. Solche hinsichtlich
    die besten je einzig dass es flexibler sollte am besten jetzt
    einladen dasjenige eine internationale mathematische zu verstehen.


  10. It’s perfect time to make some plans for the long run and it is time to be happy.

    I’ve read this submit and if I may just I wish
    to suggest you some fascinating issues or tips.
    Maybe you can write next articles relating to this article.
    I wish to learn even more issues about it!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s