Object 120-PHP calls member method as a parameter and different classes

? < PHP
     class ourself {         // define your own humanity 
        private  $ Birthday = '1990-12-20';         // define the private property of members of the modified 
        public  function say_birthday ( $ obj ) {         // define a member method 
            IF ( $ obj instanceof ourself) {         // determine whether the parameters passed to the object ourself like 
                echo . 'I was born' $ the this -> birthday;
            } The else {
                 echo 'I can not tell you my birthday. ' ;
            }
        }
    }
    class OTHER {         // define an other human
        
    }
    Tom $ = new new ourself ();         // instantiate objects themselves human 
    $ Jim = new new ourself ();         // instantiate objects themselves human 
    $ Ken = new new OTHER ();         // instantiate objects other human 
    echo ' jim want to know the tom's birthday: ' ;
     $ tom -> say_birthday ( $ jim );         // call member methods and jim as the object of the same class of parameter 
    echo ' <br /> ken want to know tom's birthday: ' ;
     $ tom -> say_birthday ( $ ken );         // object members of different classes and method calls ken as a parameter 
>?

 

Guess you like

Origin www.cnblogs.com/tianpan2019/p/11008933.html
Recommended