Home > Backend Development > PHP Tutorial > PHP 关于访问控制的和运算符优先级介绍_php技巧

PHP 关于访问控制的和运算符优先级介绍_php技巧

WBOY
Release: 2016-05-17 08:56:52
Original
1177 people have browsed it

复制代码 代码如下:

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());

访问控制

对属性或方法的访问控制,是通过在前面添加关键字 public、protected 或 private 来实现的。由 public 所定义的类成员可以在任何地方被访问;由 protected 所定义的类成员则可以被其所在类的子类和父类访问(当然,该成员所在的类也可以访问);而由 private 定义的类成员则只能被其所在类访问。

复制代码 代码如下:

$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, $b,$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());

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template