Home >Backend Development >PHP Tutorial >对象实例化后访问不了

对象实例化后访问不了

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-23 13:57:12907browse

class person{
   var $name;
   function say(){
echo "hello!";
   }
}
$P = new person;
$p->name="TOM";
$p->say();
?>


Notice: Undefined variable: p in I:\www\PHPnow-1.5.6.4237493736\Package\htdocs\DemoClass.php on line 10

Fatal error: Call to a member function say() on a non-object in I:\www\PHPnow-1.5.6.4237493736\Package\htdocs\DemoClass.php on line 10
哪里出错了,新手求教,我照着书上码的。


回复讨论(解决方案)

$P = new person;
$p->say();

php 的变量是区分大小写的
$P 和 $p 是两个变量

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn