无法访问 php 中的对象函数

发布于 2024-11-03 00:55:15 字数 2234 浏览 0 评论 0原文

这是类定义,

     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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

巴黎夜雨 2024-11-10 00:55:15
$iann->create();

不是

$iann.create();

。是连接运算符

$iann->create();

not

$iann.create();

. is the concatenation operator

向日葵 2024-11-10 00:55:15

php 中必须使用 -> 来调用方法:

$iann->create();

.net 和 java 中使用点符号,但 php 中不使用。 php 中的 . 运算符连接两个字符串,因此 php 可能会将您的 $iann 对象转换为字符串,然后尝试将其与函数 的返回值连接>create() 确实存在于全局命名空间中。

you have to use -> in php to call methods:

$iann->create();

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 function create() which does exist in the global namespace.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文