Forum Moderators: coopster
I'm trying to make an error basket - a thing where I can manually place errors and display them a given way. I was thinking about something like this:
class errors {
function array_create(){
$this->errors = array(); // creating an array
}
function add_error($content){
array_push($this->errors,$content); // adding an error
}
function display_errors(){
foreach( $this->errors as $display){
echo "Errors: " . $display . "<br>";
}
}
}
//However, the problem with that class is I cannot use it inside another class.
class someclass {
function somefunction(){
$error_22 = "File too big";
$errors->add_error($error_22); // a php error appears here ("Call to a member function on a non-object in ...")
}
}$errors = new errors();
$errors->array_create();
$errors->add_error("an error");$someclass = new someclass();
$someclass->somefunction();
$errors->display_errors();
Anyone knows a smart way to achieve that?
Thanks
Storm
class errors {
var $error = array();// Adding an error
function add($str) {
$this->error[] = $str;
}// Display errors
function display() {
foreach ($this->error as $str) {
echo "Error: " . $str. '<br>';
}
}
}$errors = new errors();
$errors->add('An error');...
$errors->display();