我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

如何访问子类php5中的受保护变量[重复]

This question already has an answer here:

  • PHP Child class accessing Parent variable problem 5 answers
<?php
class a
{
    protected $c=10;

}
class b extends a{

    echo a::$c;

    }
    //$obj = new b();

?>

Here I am trying to print the parent class variable in the child class. can you tell me how to make use of the parent class variables in child class in PHP5?

</div>
class parent {
    protected $field;
}
class child extends parent {
  public function test() {
    return $this->field;
  }
}

Doc: http://php.net/manual/en/language.oop5.visibility.php

近期文章

  • 将'if else'语句转换为PHP中的循环?
  • 警告:mysql_query()期望参数2是资源,第103行给出的字符串[重复]
  • 在一个查询中组合多个sql / mysql查询
  • 如何检查字符串是否包含3个或更多连续数字
  • 单击html链接时php变量发生变化[关闭]
  • 如何使用explode将字符串转换为数组?
  • 在PHP中使用SQL导致错误PDO语句[关闭]
  • Foreach循环php [关闭]
  • PHP - 如果在if内
  • PHP网站调试[重复]
  • 如何使用PHP显示时间表?
  • 如何在wordpress中获取缩略图
  • 如何存储图像并在网站上提供服务
  • 如何将mysql函数转换为sqlsrv? [关闭]
  • 关于在Windows中安装php
  • sql&php请给出这个错误解决方案[重复]
  • 警告:在485 496处除以零
  • 在现有项目中安装Symfony CMF
  • While循环内的循环不循环
  • 登录表单始终显示“错误的凭据”

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华