Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Build a Basic PHP Website (2018) Enhancing a Form Error Message Priority

Why not make $error_message an array?

Firstly, great video series!

Why not make $error_message an array, such as $error_message[]; and push each error to the array using a loop?

Wouldn't it be great to see all errors on the screen at once?

Is there a reason an array shouldn't be used for this?

1 Answer

Sean T. Unwin
Sean T. Unwin
28,690 Points

This is an entirely valid way (i.e. assigning all errors to an errors array). In fact, I have an error manager class for some projects at work (e.g. reading/manipulating files, ensuring they are in the correct format, correct headers, etc) where I do exactly this.

With this class I also have various levels of errors such as fatal, warning, etc. Then, when applicable, the process checks for existing errors and when errors are found they either abort the process (fatal) or give the user a warning while still being able to perform an action.

You will have to store the array someplace where it can be persistent such a global or class level variable and push each error to the array to be retrieved at some point later.

Thanks Sean, WOW! You sound advanced. I hope to get there one day! Cheers!!!