Discuss PHP access controller and operator precedence_PHP tutorial

WBOY
Release: 2016-07-20 11:12:52
Original
864 people have browsed it

<?<span php
</span><span /*</span><span *
* php访问控制器的例子
*edit by www.jbxue.com
</span><span */</span>
<span class</span><span  Foo 

{ 
</span><span private</span> <span $name</span> = 'hdj'<span ; 
</span><span public</span> <span function</span><span  getName(){ 
</span><span return</span> <span $this</span>-><span name; 
} 
}

</span><span class</span> Bar <span extends</span><span  Foo 
{ 
</span><span public</span> <span $name</span> = 'deeka'<span ; 
}

</span><span $bar</span> = <span new</span><span  Bar; 
</span><span var_dump</span>(<span $bar</span>-><span name); 
</span><span var_dump</span>(<span $bar</span>-><span getName());
</span>?>
Copy after login

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.

<span  1</span> <?<span php
</span><span  2</span> <span /*</span><span *
</span><span  3</span> <span * php访问控制 与 运算符优先级
</span><span  4</span> <span * by www.jbxue.com
</span><span  5</span> <span */</span>
<span  6</span> <span $a</span> = 3<span ;
</span><span  7</span> <span $b</span> = 6<span ;
</span><span  8</span> <span if</span>(<span $a</span> = 5 || <span $b</span> = 7<span ){
</span><span  9</span> <span echo</span> <span $b</span>.'<br />'<span ;
</span><span 10</span> <span $a</span>++<span ; 
</span><span 11</span> <span $b</span>++<span ;
</span><span 12</span> <span }
</span><span 13</span> <span var_dump</span>(<span $a</span>, <span $b</span><span );
</span><span 14</span> <span echo</span> '<br /> $a = (5 || $b = 7)'<span ;
</span><span 15</span> <span echo</span> '<hr />'<span ;
</span><span 16</span> <span $a</span> = 3<span ;
</span><span 17</span> <span $b</span> = 6<span ;
</span><span 18</span> <span $c</span> = 1<span ;
</span><span 19</span> <span if</span>(<span $a</span> = 5 || <span $b</span> = 7 && <span $c</span> = 10<span ){
</span><span 20</span> <span $a</span>++<span ; 
</span><span 21</span> <span $b</span>++<span ;
</span><span 22</span> <span }
</span><span 23</span> <span var_dump</span>(<span $a</span>, <span $b</span>,<span $c</span><span );
</span><span 24</span> <span echo</span> '<br /> && 比 || 高'<span ;
</span><span 25</span> <span echo</span> '<hr />'<span ;
</span><span 26</span> <span $a</span> = 3<span ;
</span><span 27</span> <span $b</span> = 6<span ;
</span><span 28</span> <span $c</span> = 1<span ;
</span><span 29</span> <span if</span>(<span $a</span> = 0 || <span $b</span> = 7 && <span $c</span> = 10<span ){
</span><span 30</span> <span $a</span>++<span ; 
</span><span 31</span> <span $b</span>++<span ;
</span><span 32</span> <span }
</span><span 33</span> <span var_dump</span>(<span $a</span>, <span $b</span>,<span $c</span><span );
</span><span 34</span> <span echo</span> '<br /> '<span ;
</span><span 35</span> <span echo</span> '<hr />'<span ;
</span><span 36</span> <span class</span><span  Foo {
</span><span 37</span> <span private</span> <span $name</span> = 'hdj'<span ;
</span><span 38</span> <span public</span> <span function</span><span  getName() {
</span><span 39</span> <span return</span> <span $this</span>-><span name;
</span><span 40</span> <span }
</span><span 41</span> <span }
</span><span 42</span> 
<span 43</span> <span class</span> Bar <span extends</span><span  Foo {
</span><span 44</span> <span public</span> <span $name</span> = 'deeka'<span ;
</span><span 45</span> <span }
</span><span 46</span> 
<span 47</span> <span $bar</span> = <span new</span><span  Bar;
</span><span 48</span> <span var_dump</span>(<span $bar</span>-><span name);
</span><span 49</span> <span var_dump</span>(<span $bar</span>-><span getName());
</span><span 50</span> ?>
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/440413.htmlTechArticle? = 'hdj' - Bar = 'deeka' = ( - ( - ? Access control for properties or methods , is achieved by adding the keywords public, protected or private in front. The class defined by public becomes...
.
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