无法访问 php 中的对象函数
这是类定义,
public function __construct($icontext, $ititle, $iorgs_id, $icreated_at) {
$this->context = $icontext;
$this->orgs_id = $iorgs_id;
$this->created_at = $icreated_at;
$this->title = $ititle;
}
//put your code here
//crud fonksiyonlari burda basliyor
public function create(){
$createann = mysql_query("INSERT INTO anns(context, title, orgs_id, created_at) VALUES('$this->context', '$this->title', $this->orgs_id, '$this->created_at'");
if($createann) return "Duyuru Başarıyla Eklendi"; else return "Duyuru Eklenemedi";
}
public function read($id){
$readann = mysql_query("SELECT * FROM anns WHERE id = $id");
$context = mysql_result($readann,0, "context");
$title = mysql_result($readann,0, "title");
$orgs_id = mysql_result($readann,0, "orgs_id");
$created_at = mysql_result($readann,0, "created_at");
$ann = new ann($context, $title, $orgs_id, $created_at);
return $ann;
}
public function update($id, $context, $title){
$updateann = mysql_query("UPDATE anns SET context = '$context', title = '$title' WHERE id = $id");
if($updateann) echo "Duyuru başarıyla güncellendi"; else echo "Duyuru güncellenemedi";
}
public function delete($id){
$deleteann = mysql_query("DELETE FROM anns WHERE id = $id");
if($deleteann){
echo "Duyuru başarıyla silindi";}
else{
echo "Duyuru silinemedi";}
}
//crud fonksiyonlari burda bitiyor
}
?>
这是我们从中创建对象的函数,
<?php
require_once '../include/functions.php';
require_once '../db_classes/ann.php';
$sonuc = login_check();
$iann = new ann(guvenlik($_POST['context']),guvenlik($_POST['title']), $orgs_id, 1231232);
$iann.create();
if($ann) echo "alallaal";
if(!$ann) echo "sadfasfdsdf";
?>
最后,这是我们得到的错误日志:D
PHP Fatal error: Call to undefined function create() in /var/www/pe/actions/newann.php on line 7" while reading response header from upstream
我们是 php 新手,所以这一定是我们引起的一个非常简单的错误,但我们无法找出是什么错误的。谢谢
Here is out class definition,
public function __construct($icontext, $ititle, $iorgs_id, $icreated_at) {
$this->context = $icontext;
$this->orgs_id = $iorgs_id;
$this->created_at = $icreated_at;
$this->title = $ititle;
}
//put your code here
//crud fonksiyonlari burda basliyor
public function create(){
$createann = mysql_query("INSERT INTO anns(context, title, orgs_id, created_at) VALUES('$this->context', '$this->title', $this->orgs_id, '$this->created_at'");
if($createann) return "Duyuru Başarıyla Eklendi"; else return "Duyuru Eklenemedi";
}
public function read($id){
$readann = mysql_query("SELECT * FROM anns WHERE id = $id");
$context = mysql_result($readann,0, "context");
$title = mysql_result($readann,0, "title");
$orgs_id = mysql_result($readann,0, "orgs_id");
$created_at = mysql_result($readann,0, "created_at");
$ann = new ann($context, $title, $orgs_id, $created_at);
return $ann;
}
public function update($id, $context, $title){
$updateann = mysql_query("UPDATE anns SET context = '$context', title = '$title' WHERE id = $id");
if($updateann) echo "Duyuru başarıyla güncellendi"; else echo "Duyuru güncellenemedi";
}
public function delete($id){
$deleteann = mysql_query("DELETE FROM anns WHERE id = $id");
if($deleteann){
echo "Duyuru başarıyla silindi";}
else{
echo "Duyuru silinemedi";}
}
//crud fonksiyonlari burda bitiyor
}
?>
And here is the function we create an object from it,
<?php
require_once '../include/functions.php';
require_once '../db_classes/ann.php';
$sonuc = login_check();
$iann = new ann(guvenlik($_POST['context']),guvenlik($_POST['title']), $orgs_id, 1231232);
$iann.create();
if($ann) echo "alallaal";
if(!$ann) echo "sadfasfdsdf";
?>
And last, here is the error log we got :D
PHP Fatal error: Call to undefined function create() in /var/www/pe/actions/newann.php on line 7" while reading response header from upstream
We are new to php, so it must be a very simple error we caused, but we coudn't find out what is wrong. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不是
。是连接运算符
not
. is the concatenation operator
php 中必须使用
->
来调用方法:.net 和 java 中使用点符号,但 php 中不使用。 php 中的
.
运算符连接两个字符串,因此 php 可能会将您的$iann
对象转换为字符串,然后尝试将其与函数的返回值连接>create()
确实存在于全局命名空间中。you have to use
->
in php to call methods:the dot notation is used in .net and java, but not in php. the
.
operator in php concatenates two strings, so php is probably converting your$iann
object to a string and then tries to concatenate it with the return value of the functioncreate()
which does exist in the global namespace.