note 110555 added to language.oop5.visibility

From: Date: Tue, 06 Nov 2012 13:32:36 +0000
Subject: note 110555 added to language.oop5.visibility
Groups: php.notes 
Request: Send a blank email to php-notes+get-191783@lists.php.net to get a copy of this message
<?php error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR); class A { private $private = 1; public $public = 1; function get() { return "A: $this->private , $this->public\n"; } } class B extends A { function __construct() { $this->private = 2; $this->public = 2; } function set() { $this->private = 3; $this->public = 3; } function get() { return parent::get() . "B: $this->private , $this->public\n"; } } $B = new B; echo $B->get(); echo $B->set(); echo $B->get(); ?> ?> Result is A: 1 , 2 B: 2 , 2 A: 1 , 3 B: 3 , 3 This is correct code and does not warn you to use any private. "$this->private" is only in A private. If you write it in class B it's a runtime declaration of the public variable "$this->private", and PHP doesn't even warn you that you create a variable in a class without declaration, because this is normal behavior. ---- Server IP: 213.172.110.14 Probable Submitter: 82.212.250.99 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.visibility.php Edit -- https://master.php.net/note/edit/110555 Del: integrated -- https://master.php.net/note/delete/110555/integrated Del: useless -- https://master.php.net/note/delete/110555/useless Del: bad code -- https://master.php.net/note/delete/110555/bad+code Del: spam -- https://master.php.net/note/delete/110555/spam Del: non-english -- https://master.php.net/note/delete/110555/non-english Del: in docs -- https://master.php.net/note/delete/110555/in+docs Del: other reasons-- https://master.php.net/note/delete/110555 Reject -- https://master.php.net/note/reject/110555 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#191783) next »