Home  >  Article  >  Backend Development  >  PHP Introduction to Access Control and Operator Priority_PHP Tutorial

PHP Introduction to Access Control and Operator Priority_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 15:00:29832browse

Copy code The code is as follows:

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

Access Control

Access control of properties or methods is achieved by adding the keywords public, protected or private in front. Class members defined by public can be accessed from anywhere; class members defined by protected can be accessed by subclasses and parent classes of the class in which they are located (of course, the class in which the member is located can also be accessed); and by private The defined class members can only be accessed by the class in which they are located.

Copy code The code is as follows:

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/328057.htmlTechArticleCopy the code The code is as follows: class Foo { private $name = 'hdj'; public function getName(){ return $ this-name; } } class Bar extends Foo { public $name = 'deeka'; } $bar = new Bar; va...
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