代码如下:
class Foo
{
private $name = 'hdj';
public function getName(){
return $this->name;
}
} class Bar extends Foo
{
public $name = 'deeka';
} $bar = new Bar;
var_dump($bar->name);
var_dump($bar->getName());
{
private $name = 'hdj';
public function getName(){
return $this->name;
}
} class Bar extends Foo
{
public $name = 'deeka';
} $bar = new Bar;
var_dump($bar->name);
var_dump($bar->getName());
访问控制
对属性或方法的访问控制,是通过在前面添加关键字 public、protected 或 private 来实现的。由 public 所定义的类成员可以在任何地方被访问;由 protected 所定义的类成员则可以被其所在类的子类和父类访问(当然,该成员所在的类也可以访问);而由 private 定义的类成员则只能被其所在类访问。
代码如下:
PHP
$a = 3;
$b = 6;
if($a = 5 || $b = 7){
echo $b.'
';
$a++;
$b++;
}
var_dump($a,$b);
echo '
$a = (5 || $b = 7)';
';
$a = 3;
$b = 6;
$c = 1;
if($a = 5 || $b = 7 && $c = 10){
$a++;
$b++;
}
var_dump($a,$b,$c);
echo '
&& 比 || 高';
';
$a = 3;
$b = 6;
$c = 1;
if($a = 0 || $b = 7 && $c = 10){
$a++;
$b++;
}
var_dump($a,$c);
echo '
';
echo '
';
$a = 3;
$b = 6;
if($a = 5 || $b = 7){
echo $b.'
';
$a++;
$b++;
}
var_dump($a,$b);
echo '
$a = (5 || $b = 7)';
echo '
';
$a = 3;
$b = 6;
$c = 1;
if($a = 5 || $b = 7 && $c = 10){
$a++;
$b++;
}
var_dump($a,$b,$c);
echo '
&& 比 || 高';
echo '
';
$a = 3;
$b = 6;
$c = 1;
if($a = 0 || $b = 7 && $c = 10){
$a++;
$b++;
}
var_dump($a,$c);
echo '
';
echo '
';
class Foo {
private $name = 'hdj';
public function getName() {
return $this->name;
}
}class Bar extends Foo {
public $name = 'deeka';
}$bar = new Bar;
var_dump($bar->name);
var_dump($bar->getName());