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

对象实例化后访问不了

WBOY
Release: 2016-06-23 13:57:12
Original
880 people have browsed it

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 是两个变量

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template