Fatal error: Uncaught Error: Call to undefined function

Started by robicse, Apr 16, 2023, 07:21 AM

Previous topic - Next topic

robicseTopic starter

The script generates the following error message: "Fatal error: Uncaught Error: Call to an undefined function count People() in C:\OpenServer\domain\vpohodenot\feedback.php:253". Despite the assertion that the function exists, there seems to be an issue. What could it be?


Functions can be used without prior definition, except in cases where they are conditionally defined, as seen in the two examples.
When a function is defined based on some condition, such as those shown in the examples, the description of the function must be processed before it is called.

PHP functions and classes can be accessed globally, regardless of whether they were defined inside or outside of a function.

Function overloading is not supported in PHP, and it is also impossible to override or delete a previously declared function.

Executive Modcar

The notice level errors are turned off, which is not recommended. The message "nothing was found" appears because the countPeople($result) function is called before querying the database and the $result variable is undefined.

Additionally, it's not ideal to have any HTML output inside a function, as it may create issues if the layout becomes more complex. Instead, forming an array of data and substituting it into the template is better. It's also possible to move functions to a separate file and include them.

In this case, for a simple search and to retrieve data from the database, using the GET method instead of POST is recommended.