Example In Changes in PHP 5/Zend Engine 2.0
From: Chong Wee Huat (chongwh_at_yahoo.com)
Date: 11/16/03
- Next message: Keith Greene: "Re: [PHP] What is "white space""
- Previous message: Leif K-Brooks: "Re: [PHP] What is "white space""
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
To: php-general@lists.php.net Date: Sun, 16 Nov 2003 07:50:22 +0800
Below is the first php example found in "Changes in PHP 5/Zend Engine
2.0 "
<?php
class MyClass {
private $Hello = "Hello, World!\n";
protected $Bar = "Hello, Foo!\n";
protected $Foo = "Hello, Bar!\n";
function printHello() {
print "MyClass::printHello() " . $this->Hello;
print "MyClass::printHello() " . $this->Bar;
print "MyClass::printHello() " . $this->Foo;
}
}
class MyClass2 extends MyClass {
protected $Foo;
function printHello() {
MyClass::printHello(); /* Should print
*/
print "MyClass2::printHello() " . $this->Hello; /* Shouldn't
print out anything */
print "MyClass2::printHello() " . $this->Bar; /* Shouldn't
print (not declared)*/
print "MyClass2::printHello() " . $this->Foo; /* Should print
*/
}
}
$obj = new MyClass();
print $obj->Hello; /* Shouldn't print out anything */
print $obj->Bar; /* Shouldn't print out anything */
print $obj->Foo; /* Shouldn't print out anything */
$obj->printHello(); /* Should print */
?>
The result not same as stated in the remark. No print for
$obj->printHello().
It only print with the code below
$obj = new MyClass();
//print $obj->Hello; /* Shouldn't print out anything */
//print $obj->Bar; /* Shouldn't print out anything */
//print $obj->Foo; /* Shouldn't print out anything */
$obj->printHello(); /* Should print */
Accessing protected variable cause the output fail, why?
- Next message: Keith Greene: "Re: [PHP] What is "white space""
- Previous message: Leif K-Brooks: "Re: [PHP] What is "white space""
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|