Define a worker class Worker, which has five attributes of name, gender, age, occupation, and mode of transportation, two methods, job and work, instantiate the class, get a worker object $workerone, call the method inside the class job, and then Instantiate a worker object $workertwo, modify the name, age, gender and position through $workertwo, use $wokertwo to call the job method, and the running effect is as follows:
1. Define the worker class Worker
2. Define the five attributes and methods of the subject requirements
3. The content of the red box in the rendering must be obtained by calling the work method
4. Instantiate the first object and call the job method
5. Instantiate the second object, modify the properties, and call the job method.
<? php // Define a class named Worker Class Worker { // Define five attributes public $name = 'Xiaohong' ; public $age = '19' ; public $sex = 'female' ; public $job = 'warehouse registrar' ; public $trc_mode = 'subway' ; / / Define two methods public function job(){ echo 'name:'. $this ->name.'<br>' ; echo 'age:'. $this ->age.'<br>' ; echo 'gender :'. $this ->sex.'<br>' ; echo 'Occupation:'. $this->job.'<br>'; $this->work(); } public function work(){ // Output who I am and what kind of transportation I take to go to work every day echo 'I am'. $this ->name.', I take '. $this ->trc_mode.' to go to work every day <br>' ; } } // Instantiate the object $workone = new Worker(); // Call the job method $workone -> job(); // Instantiate another object $worktwo = new Worker(); // Modify properties $worktwo ->name='Xiaohuang' ; $worktwo ->sex='male' ; $worktwo ->job='workshop operator' ; // Call job method with second object $worktwo - > job(); ?>