类Person的对象无法转换为字符串 [英] Object of class Person could not be converted to string

查看:84
本文介绍了类Person的对象无法转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

允许我的构造函数接受参数的代码:


<?php

class Person {

function __construct ($ name)

{

$ this-> name = $ name;

}


function getName()

{

返回$ this->名称;

}


function printName()

{

print $ this-> name;

}


private $ name;

}


$ judy = new Person(Judy)。 " \\\
英寸; //< - 这是行解析器不要

喜欢

$ joe = new Person(Joe)。 " \ n";


$ judy-> printName()。 ''< br />'';

$ joe-> printName()。 ''< br />'';

?>


输出:


可捕获致死错误:类的对象无法转换

到字符串


之前有人见过吗?知道为什么?我在这里遗漏了什么吗?


谢谢大家...


Gene Kelley

LAMP Web开发人员

bizFlowDesigns.com

Code which should allow my constructor to accept arguments:

<?php
class Person {
function __construct($name)
{
$this->name = $name;
}

function getName()
{
return $this->name;
}

function printName()
{
print $this->name;
}

private $name;
}

$judy = new Person("Judy") . "\n"; // <- this is line parser don''t
like
$joe = new Person("Joe") . "\n";

$judy->printName() . ''<br />'';
$joe->printName() . ''<br />'';
?>

Outputs:

Catchable fatal error: Object of class Person could not be converted
to string

Anyone seen this before? Know why? Am I missing something here?

Thanks all...

Gene Kelley
LAMP Web Developer
bizFlowDesigns.com

推荐答案

名称)

{
name)
{


this-> name =
this->name =


name;

}


function getName()

{

return
name;
}

function getName()
{
return


这篇关于类Person的对象无法转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆