Undefined Variable 500 Error |
PHP Code: <?php The above code generates 500 internal server errors in a real environment. In native php this code continues normally. In Ci3 it also logs the undefined error to the logs folder but the script continues to run. Is it possible to make this situation work like ci3 in ci4?
Please read dd() in the CodeIgniter 4 User Guide.
Enabling Kint What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Quote:In most cases, accessing an undefined variable is a severe programming error. The current low classification is a legacy from the Dark Ages of PHP, where features like register_globals made conditionally defined variables more typical, and code quality standards were lower.In PHP 8.0 or later, undefined variable is a severe programming error.
You code has another critical error. The method must return a string, but nothing is returned.
You must remove `: string`. PHP Code: public function index(): string
If you use PHP 7.4, and if you use CI4 in production mode (by default, CI4 starts up in production mode),
the following code shows "okay". PHP Code: <?php
Php Version : 8.3.3 and 8.1.1 use
Even if you remove the string return of the function, the problem is not solved. Yes, it is a strict rule that there should be no undefined variables in advanced programming languages. However, this is not the case in php. ci4 interrupts the process directly in exception for undefined variable. I connect to dozens of different api services in my project. and if the api service does not return the variable I want in any different problem, the script should not stop running. this is not just a variable, you can think of it as an array or json object. If the dynamic response you get from the api does not have the array element you want, it should not stop the code with an undefined 500 error. We have gotten used to and accepted this usage for years on the php side. How can I ensure that it does not give a 500 server error in undefined variable error for ci4 and continue the script? [Video: https://www.youtube.com/watch?v=8Tfks2LS78g]
In the video, you removed ini_set() and error_reporting() in the plain php script.
If you set the same error level in CI4, the result will be the same. Ediit app/Config/Boot/production.php (12-19-2023, 02:55 AM)mywebmanavgat Wrote: Yes, it is a strict rule that there should be no undefined variables in advanced programming languages. However, this is not the case in php. I'm sorry, but the idea is outdated. You might not like it, but now PHP is getting to be an advanced programming languages. Errors is getting stricter and stricter, type definitions are everywhere. Dynamic properties are not allowed by default. I recommend you fix your code so that no error occurs. This is why an error is displayed.
doing this solves the problem in the output.
however, ci4 never logs this error. Thank you for your help. I think I need to think a little and decide whether I will continue with ci3 or laravel. there are too many contradictions in ci4. Since errors are not logged, you cannot debug them.
That is strange.
CI3 also does not log the Notice error in production mode. |
Welcome Guest, Not a member yet? Register Sign In |