Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom Class not displaying echo
    text
    copied!<p>I have been trying to write a class to be used for displaying errors and error log. </p> <pre><code>class CError { //Error Logging var $Log; public function Log($Comment, $Detail = ""){ $Log .= $Comment . "\n"; if ($Detail !== ""){ $Log .= "--" . $Detail . "--\n"; } } public function Clear_Log(){ $Log = ""; } public function Display_Log(){ echo $this-&gt;Log; } //Error Display var $ErrorCode = array( 0 =&gt; "0: No Error Code found, so either you got here by some rogue code or ...", 1 =&gt; "1: General Error, if you are here something went wrong", 2 =&gt; "2: Invalid information provided", 3 =&gt; "3: Alternate path taken, check message for details", 42 =&gt; "42: Here is your answer, but do you know the question?", 50 =&gt; "50: You messed with the Creepers without your Diamond Sword, didn't you", 9001 =&gt; "9001: Its over 9000... or more likely a value used was to large", 418 =&gt; "418: I'm a Teapot, found the error that drove you crazy" ); public function Error($Error = 0, $ShowLog = false){ if ($Error === ""){ $Error = 0; } foreach ($ErrorCode as $key =&gt; $value){ if($key == $Error){ echo "&lt;h3 style='color:red'&gt;" . $value . "&lt;/h3&gt;&lt;br /&gt;"; } } if($ShowLog == true){ echo $this-&gt;Log; } } </code></pre> <p>}</p> <p>This is how I use the error class</p> <pre><code>include 'CError.php'; $Error = new CError; $Error-&gt;Log("Email is Required"); $Error-&gt;Display_Log(); $Error-&gt;Error(2,true); </code></pre> <p>The problem is, nothing is displayed when used. It is skipped I think but not sure. I do not have access to the error logs for the server so I do not know if an error is being produced or not but the code will run through to the exit points in my main code(irrelevant to the class)</p> <p>--EDIT--</p> <p>The answers that tell to change $Log with $this->Log has fixed the issue with the $Log variable. It still has not fixed the issue with the error code array being displayed in the foreach loop.</p> <p>--EDIT--</p> <p>I solved the issue by adding $this->ErrorCode to the foreach loop.</p>
 

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