search
Homephp教程php手册PHP 关于访问控制的和运算符优先级介绍

这篇文章主要介绍了PHP中关于访问控制的和运算符优先级介绍,需要的朋友可以参考下

复制代码 代码如下:


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

,香港空间,服务器空间
Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools