rick645 Posted January 25, 2023 Share Posted January 25, 2023 $ php -v PHP 8.1.2-1ubuntu2.10 (cli) (built: Jan 16 2023 15:19:49) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.2, Copyright (c) Zend Technologies with Zend OPcache v8.1.2-1ubuntu2.10, Copyright (c), by Zend Technologies $ cat entry-point.php <?php error_reporting(E_ALL & ~E_WARNING & ~E_USER_WARNING); class C { final private function m() {} } $ php entry-point.php PHP Warning: Private methods cannot be final as they are never overridden by other classes in /tmp//entry-point.php on line 6 Ok, the appropriate WARNING appears. However, since there is error_reporting(...) instruction, it should not appear. Why do you appear? Quote Link to comment https://forums.phpfreaks.com/topic/315839-error_reporting-hide-the-warnings/ Share on other sites More sharing options...
requinix Posted January 25, 2023 Share Posted January 25, 2023 error_reporting() won't help you if there is an error detected while parsing the file that the code is in. In this case, since there is no other file where you could put the function call, set the error reporting you want with a CLI option. You know what's even better though? Fixing the problem the warning is telling you about. Quote Link to comment https://forums.phpfreaks.com/topic/315839-error_reporting-hide-the-warnings/#findComment-1605028 Share on other sites More sharing options...
rick645 Posted January 25, 2023 Author Share Posted January 25, 2023 $ cat entry-point.php <?php var_dump(ini_get('error_reporting')); class C { final private function m() {} } $ cat php.ini error_reporting = E_ALL & ~E_WARNING & ~E_USER_WARNING $ php entry-point.php PHP Warning: Private methods cannot be final as they are never overridden by other classes in /tmp//entry-point.php on line 4 string(5) "22527" Comprehensible!!! $ php -c php.ini entry-point.php Warning: Private methods cannot be final as they are never overridden by other classes in /tmp//entry-point.php on line 4 string(5) "32253" Now I do not understand... Quote Link to comment https://forums.phpfreaks.com/topic/315839-error_reporting-hide-the-warnings/#findComment-1605029 Share on other sites More sharing options...
Phi11W Posted January 25, 2023 Share Posted January 25, 2023 Your problem is this line: 9 minutes ago, rick645 said: final private function m() {} A private function is accessible only within the class in which it is defined (your class, "C"). A final function is one that is known to subclasses (of "C"), but those subclasses are not permitted to override that function. Since a private function is not known to subclasses, it cannot be meaningfully marked as final, hence the Warning. Either remove the final modifier or change the "private" modifier to "protected". Protected functions are known to subclasses and, by default, can be overridden by those subclasses. Neither private nor protected functions are available to any other class. See also Visibility in the Documentation. Regards, Phill W. Quote Link to comment https://forums.phpfreaks.com/topic/315839-error_reporting-hide-the-warnings/#findComment-1605030 Share on other sites More sharing options...
rick645 Posted January 25, 2023 Author Share Posted January 25, 2023 (edited) That's not the point. The point is, because error_reporting = E_ALL & ~E_WARNING & ~E_USER_WARNING doesn't work. Edited January 25, 2023 by rick645 Quote Link to comment https://forums.phpfreaks.com/topic/315839-error_reporting-hide-the-warnings/#findComment-1605031 Share on other sites More sharing options...
Solution Barand Posted January 25, 2023 Solution Share Posted January 25, 2023 The point is that that your code to set the error reporting level is not being executed. When you run a PHP script is is first parsed for errors (startup errors). If none are found the script is then executed (and your error reporting code will be executed) but, as in this case, if errors are found your code is not executed. This was pointed out to you by requinix earlier... 1 hour ago, requinix said: error_reporting() won't help you if there is an error detected while parsing the file that the code is in. Quote Link to comment https://forums.phpfreaks.com/topic/315839-error_reporting-hide-the-warnings/#findComment-1605032 Share on other sites More sharing options...
requinix Posted January 25, 2023 Share Posted January 25, 2023 Also, the warning is during compilation, which makes it a E_COMPILE_WARNING and not a regular runtime E_WARNING. Quote Link to comment https://forums.phpfreaks.com/topic/315839-error_reporting-hide-the-warnings/#findComment-1605041 Share on other sites More sharing options...
rick645 Posted January 26, 2023 Author Share Posted January 26, 2023 Thanks for the info Quote Link to comment https://forums.phpfreaks.com/topic/315839-error_reporting-hide-the-warnings/#findComment-1605066 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.