简体   繁体   中英

PHP Fatal error: Call to a member function smileysboxrep() on a non-object in

When I add a PHP function, it shows me the above error on the server error page. Where is my problem?

smileysboxall.php

class kochClass {

     function smileysboxrep($Sid){
echo'<img src="../smile.gif" alt=":)" class="embtno" id="'.$Sid.'" />
     <img src="../sad.gif" alt=":(" class="embtno" id="'.$Sid.'" />
     <img src="../biggrin.gif" alt=":-D" class="embtno" id="'.$Sid.'" />';
     }

     function smileysboxcom($id){
echo'<img src="../smile.gif" alt=":)" class="embtn" id="'.$id.'" />
     <img src="../sad.gif" alt=":(" class="embtn" id="'.$id.'" />
     <img src="../biggrin.gif" alt=":-D" class="embtn" id="'.$id.'" />';
     }
}
$kochClass = new kochClass();

Call function at index.php

// Query and echoing
$Sid = $rows['s_id'];
include_once("smileysboxall.php");
if ($Sid){ echo ''.$kochClass->smileysboxrep($Sid).'';}

The issue is because the include_once .

Actually include_once is going to include your code just once and maybe in another file so your $kochClass = new kochClass(); doesn't exists in index.php.

Just move $kochClass = new kochClass(); in index.php .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM