我现在自己编写了一个两个继承关系的类,父类实例化后子类不知道怎么调用父类已经实例后存储的变量
先把代码粘在下面:
class identification{ //identification函数将name与code联系起来 public function identification() { //连接到infomodel $db_info = m('info'); $condition->name = $this->name; return $this->code = $db_info->where($condition)->getfield('code'); } public $name; protected $code;}class pt_info extends identification{ public function get_bloodtest() { $db_bloodtest = m('bloodtest'); $condition->code = $this->code; echo "this is code:".$this->code; $this->info_bt_wbc = $db_bloodtest->where($condition)->getfield('wbc'); echo "this is wbc:".$this->info_bt_wbc; $this->info_bt_neper = $db_bloodtest->where($condition)->getfield('neper'); echo "this is ne%:".$this->info_bt_neper; $this->info_bt_lyper = $db_bloodtest->where($condition)->getfield('ly%'); echo "this is ly%:".$this->info_bt_lyper; $this->info_bt_moper = $db_bloodtest->where($condition)->getfield('mo%'); echo "this is mo%:".$this->info_bt_moper; } public $info_bt_wbc; public $info_bt_neper; public $info_bt_lyper; public $info_bt_moper;}public function tclass() { $neal = new identification(); $neal->name = 'neal'; $code = $neal->identification(); $this->assign('name',$neal->name); $this->assign('code',$code); $neal_bt = new pt_info(); $neal_bt->get_bloodtest(); $this->assign('info_bt_wbc',$neal_bt->info_bt_wbc); $this->assign('info_bt_neper',$neal_bt->info_bt_neper); $this->assign('info_bt_lyper',$neal_bt->info_bt_lyper); $this->assign('info_bt_moper',$neal_bt->info_bt_moper); $this->display(); }
2010-10-31日最新更正: 一、更正了产品及文章无限分类不能显示继承类别的bug. 二、更正了产品名称标题过长导致页面布局错位的bug. 随缘企业网站管理系统(无限级分类红色版)简介: 一、全站采用主流DIV+CSS框架布局,宽屏红灰主色调,简洁大方。适合各类行业作为企业站使用。 二、后台可对相关的网站标题,关键词,描述、底部版权信息等进行设置,同时可指定相关的安装目录,可在二级目录使用。
0
你的概念出问题了
Class PT_Info extends Identification 后
PT_Info 和 Identification 就是两个独立的类了,虽然 PT_Info 继承了 Identification 一些东西
这就和 你 不是 你父亲 是一个道理
Class Identification
{
public function Identification()
你在 Identification 定义了 Identification 方法,这就是构造函数了(据说 php7 取消了这个 C++ 来的特征)
那么,你在实例化 PT_Info 时,这个 Identification 方法就会自动被执行 code 属性就已经有值了
注意:构造函数是没有返回值的(写了也没用)
因此 tclass 方法中的 $neal = new Identification(); 是没有意义的
后面还有 $neal_BT = new PT_Info();
就是说 $DB_Info->where($condition)->getfield('Code'); 被执行了两次,多了一次无用功
你的概念出问题了
Class PT_Info extends Identification 后
PT_Info 和 Identification 就是两个独立的类了,虽然 PT_Info 继承了 Identification 一些东西
这就和 你 不是 你父亲 是一个道理
Class Identification
{
public function Identification()
你在 Identification 定义了 Identification 方法,这就是构造函数了(据说 php7 取消了这个 C++ 来的特征)
那么,你在实例化 PT_Info 时,这个 Identification 方法就会自动被执行 code 属性就已经有值了
注意:构造函数是没有返回值的(写了也没用)
因此 tclass 方法中的 $neal = new Identification(); 是没有意义的
后面还有 $neal_BT = new PT_Info();
就是说 $DB_Info->where($condition)->getfield('Code'); 被执行了两次,多了一次无用功
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
C++高性能并发应用_C++如何开发性能关键应用
Java AI集成Deep Java Library_Java怎么集成AI模型部署
Golang后端API开发_Golang如何高效开发后端和API
Python异步并发改进_Python异步编程有哪些新改进
C++系统编程内存管理_C++系统编程怎么与Rust竞争内存安全
Java GraalVM原生镜像构建_Java怎么用GraalVM构建高效原生镜像
Python FastAPI异步API开发_Python怎么用FastAPI构建异步API
C++现代C++20/23/26特性_现代C++有哪些新标准特性如modules和coroutines
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号