您好我一直试图在PHP中以多种不同的方式调用对象“person”上的函数,但没有成功。在SO上有一个类似的问题,它有一个对我不起作用的解决方案。使用' - >'调用任何函数运算符导致错误。在多个浏览器中测试,因此不是缓存问题。运行PHP 5.6.30
非常感谢
<html>
<?php
class Person
{
public $Name;
public $Surname;
public $City;
public function __construct( )
{
//$this->Name = $p1;
//$this->Surname = $p2;
}
public function FullName()
{
echo "FULL NAME FUNCTION";
//return $this->Name . " " . $this->Surname;
}
}
?>
<head>
<title> Information Gathered </title>
</head>
<body>
<?php
echo "ALIVE" ;
$userName = $_POST['username'];
$surname = $_POST['surname'];
$city = $_POST['city'];
//echo "Hello". $userName . "</br>";
//echo $surname . "</br>";
//echo "from" . $city . "</br>";
//$SubmitedPerson = new Person($userName, $surname);
$SubmitedPerson = new Person;
$m_instance = SubmitedPerson->instance();
//SubmitedPerson::instance();
//SubmitedPerson->FullName();
//echo $fullname;
?>
</body>
答案 0 :(得分:1)
您在SubmitedPerson前面缺少美元符号 $ 。 您的代码应如下所示:
$SubmitedPerson = new Person;
$SubmitedPerson->FullName();