Advertisement
Guest User

Untitled

a guest
Dec 14th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. class User{
  2. public $email;
  3. private $password = '1234'; //assigned here for simplicity
  4. //same happens when assign from
  5. //inside a class
  6. }
  7.  
  8. require './lib/User.php';
  9. $john = new User();
  10. $john->email = 'john@email'; //$email is public
  11.  
  12. var_dump($john->password); //$password is private
  13.  
  14. Fatal error: Uncaught Error: Cannot access private property User::$password in /home/pl/work/php/index.php:20 Stack trace: #0 {main} thrown in /home/work/php/index.php on line 5
  15.  
  16. var_dump($john);
  17.  
  18. object(User)#1 (2) { ["email"]=> string(10) "john@email" ["password":"User":private]=> string(4) "1234" }
  19.  
  20. PHP 7.0.8-0ubuntu0.16.04.3 (cli) ( NTS )
  21. Copyright (c) 1997-2016 The PHP Group
  22. Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
  23. with Zend OPcache v7.0.8-0ubuntu0.16.04.3, Copyright (c) 1999-2016
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement