Skip to content
Advertisement

PHP show full list of errors in a array

I use OOP and i wanted to ask you guys how this would be done! I keep trying but its still not working ;(
Here is my class file:

JavaScript

Here is my signup file

JavaScript

I know That im calling the $error in the same file and not the property error. But i dont know how to send this array to the other file! Please help me! Also i have Called everything and the problem is just with my code(i think), i only included my file and made a var to call my signup class

Advertisement

Answer

  1. It is never too early in your development career to study coding standards. Jump straight to PSR-12, and adopt all of these guidelines to write beautiful, professional code.

  2. Use data type declarations in your classes where possible, it will improve the data integrity throughout your project(s).

  3. You appear to prefer returning an array of errors. For this reason, I see no benefit in caching the errors long-term in a class property. This coding style is fine to do, but you could choose to return nothing (void) and instead populate a class property $errors, then access it directly after the $signup->validate() call via $signup->errors or use a getter method.

  4. The empty() checks are too late in the flow. Once the values have been passed to the class method, these values must already be declared. For this reason empty() is needless overhead to check for mere “falsiness”. Just check the values’ string length.

  5. Your data quality checks seem a little immature (email and password checks should be much more complex), but I won’t confuse you with any new complexity, but I do expect that your validation rules will increase as you realize that users cannot be trusted to put good values in forms without be forced to do so. For this reason, it is probably unwise to use a loop to check the value lengths because you will eventually need to write individual rules for certain values.

A possible write up:

JavaScript

When calling this method…

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement