PHP extended class inheritance -
i have base of operations class extending, can't work out why variables defining in base of operations class arn't accessible kid class. understood had protected allow access, still won't work me.
class user { protected static $username; protected static $password; protected static $remember; function __construct() { } public function login($username, $password, $remember) { $this->username = $username; $this->password = $password; $this->remember = $remember; $login = new login(); } } class login extends user { function __construct() { print("user is: " . $this->username); die(); } }
you variables in base of operations class static , improve understand of inheritance.
you need instead:
class user { protected $username; protected $password; protected $remember; public function __construct($username, $password, $remember) { $this->username = $username; $this->password = $password; $this->remember = $remember; } } class login extends user { public function __construct($username, $password, $remember) { parent::__construct($username, $password, $remember); print("user is: " . $this->username); } } $user = new login('joe bloggs', 'a password', true);
php
No comments:
Post a Comment