问一个有关PHP类变量问题

最帅马老师 2010-06-11 10:18:46
请教前辈,有一个PHP类,希望它中的一个变量也是一个类对象,该如何做:



class a
{
// class body
}

class b
{
public vtest;

function b()
{
$this->vtest = new a; // 这样做好像不起作用
}
}


如何让类b中的vtest变量赋值成一个a类的对象?
...全文
115 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
最帅马老师 2010-06-11
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 dingsongtao 的回复:]

PHP code

class a{
function echos($str){
echo $str;
}
}
class b{
public $vtest=NULL;

function b(){
$this->vtest = new a;
}
}
$b=new b;
$b->vtest->echos("12345"……
[/Quote]

怪异,多谢,我再检查下
Dleno 2010-06-11
  • 打赏
  • 举报
回复

class a{
function echos($str){
echo $str;
}
}
class b{
public $vtest=NULL;

function b(){
$this->vtest = new a;
}
}
$b=new b;
$b->vtest->echos("12345");
//12345


怎么就不起作用了呢?
最帅马老师 2010-06-11
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 jianglin28290 的回复:]

class a
{
// class body
}

class b
{
public $vtest;

function b()
{
$this->vtest = new a; // 这样做好像不起作用
}
}
[/Quote]

那个是笔误
jianglin28290 2010-06-11
  • 打赏
  • 举报
回复
class a
{
// class body
}

class b
{
public $vtest;

function b()
{
$this->vtest = new a; // 这样做好像不起作用
}
}

21,893

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧