PHP Introduction to access control and operator precedence _php tips

Source: Internet
Author: User
Tags php introduction

Copy Code code 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 on a property or method is implemented by adding the keyword public, protected, or private earlier. A class member defined by public can be accessed anywhere; A class member defined by protected can be accessed by subclasses and the parent class of the class in which it resides (of course, the class in which the member is also accessible), whereas a class member defined by private can only be accessed by its class.

Copy Code code as follows:

<?php
$a = 3;
$b = 6;
if ($a = 5 | | $b = 7) {
echo $b. ' <br/> ';
$a + +;
$b + +;
}
Var_dump ($a, $b);
Echo ' <br/> $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 ' <br/> && | | High ';

echo ' $a = 3;
$b = 6;
$c = 1;
if ($a = 0 | | $b = 7 && $c = 10) {
$a + +;
$b + +;
}
Var_dump ($a, $b, $c);
echo ' <br/> ';
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 ());

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.