探讨 PHP 访问控制器与运算符优先级_PHP教程

WBOY
發布: 2016-07-20 11:12:52
原創
862 人瀏覽過

<?<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>?>
登入後複製

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

<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> ?>
登入後複製

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/440413.htmlTechArticle? = 'hdj' - Bar = 'deeka' = ( - ( - ? 对属性或方法的访问控制,是通过在前面添加关键字 public、protected 或 private 来实现的。由 public 所定义的类成...
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板