Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Person
- {
- protected $name;
- protected $age;
- public function __construct($name)
- {
- $this->name=$name;
- }
- public function setAge($age)
- {
- if($age<18)
- {
- throw new Exception("Error Processing Request");
- }
- $this->age=$age;
- }
- public function getAge()
- {
- return $this->age;
- }
- }
- $asad=new Person('Asad');
- $asad->setAge(20);
- //$asad->age=2;
- echo $asad->getAge();
Advertisement
Add Comment
Please, Sign In to add comment