Note that there are some explanatory texts on larger screens.

plurals
  1. POphp trait using another trait
    primarykey
    data
    text
    <p>I have a trait which is using another trait, and now I'm getting errors about functions that don't exist in classes. I have simplified the code:</p> <p>settings.php:</p> <pre><code>&lt;?php trait settings{ protected function getSetting($type, $setting){ // read setting from config.ini try{ $configFile=dirname(__FILE__)."/../config.ini"; if(!file_exists($configFile)||!is_file($configFile))throw new Exception("Config file was not found. "); $configContents=parse_ini_file($configFile,true); if(is_array($configContents)&amp;&amp;array_key_exists($type,$configContents)&amp;&amp;is_array($configContents[$type])&amp;&amp;array_key_exists($setting,$configContents[$type]))return $configContents[$type][$setting]; else throw new Exception("Setting ".$setting." could not be found in ".$type."."); } catch(Exception $e){throw new Exception($e-&gt;getMessage());} } } ?&gt; </code></pre> <p>database.php</p> <pre><code>&lt;?php trait database{ use settings,session; private $pdo; protected function connect(){ // connect to database try{ $this-&gt;pdo=new PDO("mysql:host=".$this-&gt;getSetting("db","host").";dbname=".$this-&gt;getSetting("db","database"),$this-&gt;getSetting("db","user"),$this-&gt;getSetting("db","password")); $this-&gt;init(); } catch(PDOException $e){throw new Exception($e-&gt;getMessage());} } } ?&gt; </code></pre> <p>users.php</p> <pre><code>&lt;?php class users{ use database; public function __construct(){ try{ $this-&gt;connect(); } catch(Exception $e){throw new Exception($e-&gt;getMessage());} } public function __destruct(){ unset($this); } public function isAdmin(){ try{ if($this-&gt;loginStatus()===true){ } else return false; } catch(Exception $e){throw new Exception($e-&gt;getMessage());} } public function loginStatus(){ if(!$this-&gt;getSession("tysus")||!$this-&gt;getSession("tyspw"))return false;// user is not logged in because we couldn't find session with username and/or password if(!$this-&gt;userExists($this-&gt;getSession("tysus"),$this-&gt;getSession("tyspw")))return false;// user is unknown to database return true;// other checks failed, user must be logged in } } ?&gt; </code></pre> <p>And now I'm getting this error:</p> <blockquote> <p>Fatal error: Call to undefined method users::readSetting() in /home/deb2371/domains/nonamenohistory.com/public_html/include/classes/class.database.php on line 18</p> </blockquote> <p>What I thought would happen was something like this: Class users uses trait database and trait database would use trait settings and trait session.</p> <p>If that was the case, I wouldn't get any errors, but unfortunately this isn't the case.</p> <p>Does someone know how to fix this problem?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload