I have a mini framework to generate my elements, make js / ajax requests interactions and interact with BD MySQL based on some patterns.
I've been using it for quite some time now, but I'm looking forward to a little increase and to insert a kind of debugger into the framework.
A very simple example:
public function mask( string $mask = 'undefined')
{
$this->mask = ' data-input-mask="' . $mask . '" ';
return $this;
}
This method is within the class responsible for the assembly of the element 'input'
, and grouping with the other methods the call is made as follows:
$input = new \vidbModel\inputElement();
$field = $input
->type('text')
->field('cpf')
->mask('cpf')
->name('cpf')
->validator('cpf')
->value(null)
->input(0);
In this example, if I call the method and insert an array in the ->mask
initiator, I get the following error message:
Fatal error: Uncaught TypeError: Argument 1 passed to vidbModel \ inputElement :: mask () must be of the type string, given in /opt/lampp/htdocs/VIDB/docs/inputs.php on line 25 and defined in /opt/lampp/htdocs/VIDB/model/inputElement.php:78 Stack trace: # 0 /opt/lampp/htdocs/VIDB/docs/inputs.php(25): vidbModel \ inputElement-> mask Array) # 1 {main} thrown in /opt/lampp/htdocs/VIDB/model/inputElement.php on line 78
What I want to do is this:
Receiving this error so that I can treat and bring a friendlier message about the error, convert that native message written above into something like:
Error encountered [0001], an array was passed as a parameter to the mask () method, the input must be done with a string only, to check an example: link
I checked one but found nothing about how to do this.
Is it possible to handle native PHP errors?
Is there a translation for PHP errors? (Although I would not be interested in this, just out of curiosity)