Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User{
- public $email;
- private $password = '1234'; //assigned here for simplicity
- //same happens when assign from
- //inside a class
- }
- require './lib/User.php';
- $john = new User();
- $john->email = 'john@email'; //$email is public
- var_dump($john->password); //$password is private
- 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
- var_dump($john);
- object(User)#1 (2) { ["email"]=> string(10) "john@email" ["password":"User":private]=> string(4) "1234" }
- PHP 7.0.8-0ubuntu0.16.04.3 (cli) ( NTS )
- Copyright (c) 1997-2016 The PHP Group
- Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
- with Zend OPcache v7.0.8-0ubuntu0.16.04.3, Copyright (c) 1999-2016
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement