daily pastebin goal
69%
SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 112 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. class User
  3. {
  4.     public $firstName;
  5.     public $lastName;
  6.     public $email;
  7.  
  8. function __construct(){
  9.     echo "Constructor in action";
  10. }
  11.  
  12. function setFirstName($fname){
  13.     $this->firstName = $fname;
  14. }
  15.  
  16. function setLastName($lname){
  17.     $this->lastName = $fname;
  18. }
  19.  
  20. function setEmail($email){
  21.     $this->email = $fname;
  22. }
  23.  
  24. function __toString(){
  25.     return $this->firstName." ".$this->lastName." ".$this->email;
  26. }
  27.  
  28. function __destruct(){
  29.     echo "Class destroyed";
  30. }
  31.  
  32. }
  33.  
  34. $user = new User();
  35.  
  36. $user->setFirstName("John")->setLastName(" Doe")->setEmail(" email@email.com");
  37.  
  38. echo $user;
  39. ?>
  40.      
  41. PHP Fatal error: Uncaught Error: Call to a member function setLastName() on null in index.php:36 Stack trace: #0 {main} thrown in index.php on line 36
  42.      
  43. $user = new User();
  44. $user->setFirstName("John");
  45. $user->setLastName("Doe");
  46. $user->setEmail("John@doe.com");
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top