Declaring strict types only applies to the file that makes the declaration unlike error reporting and ini_set(‘display_errors’, ‘true’); which apply to all include/require files.
I prefer knowing exact requirements rather than relying upon PHP Type Juggling which may create future problems.
ini_settings are best set in the php.ini file and should be set to only show show errors and warnings when developing locally.
Error reporting should always be set to -1 which is the maximum error reporting. Online Log file should be checked frequently.
Everything you say makes sense and seems like good advice thank you. The only part I do not fully understand is the first paragraph. I think you are warning me that
1 - declaring strict types will NOT apply to included / required files
ini_set() will apply to the file that declared it and files included and required by that file
3 - I should always try and use strict types and therefore the correct syntax would then be
ini_set(‘display_errors’, ‘true’); rather than ‘1’ or 1
My idea for development would be to use a global require file that sets strict types and error reporting and logging options and then on the production system I could simply amend the global require file and add ini settings to the server php.ini file does that sound reasonable
I forgot to mention that require(strict_types=1); must be the first declaration/statement and cannot be included or required. The idea is that the declaration only applies to that file and does not affect any old libraries which most probably fail strict validation.
There is no need to include a configuration file instead the error_reporting and ini_set statements should be set in “php.ini”.
The ONLINE “php.ini” should not ‘display_errors’.
It is advisable to copy the old “php.ini” to a new file and ensure the new “php.ini” settings are working. If there are errors they are not shown and default “php.ini” setting are used.
After making changes, on Linux it is necessary to call the following in the Command Box to activate the new settings:
systemctl restart apache2
Thanks for clarification, will be most helpful
When creating methods I prefer adopting the following method templates:
Public function getUserDetails
$aUserDetails = getUserDetails(‘Joe_Blogs’);
$username = ‘just testing’
: array // empty if no valid user
$result = ;
// script to search for user details and return array of $results
if ($found) :
// fill array
}// end getUserDetails
I will follow your advice - just as soon as I know what a method is
If you have any links to good resources for very basics / introduction to OOP that would be great!
I do not know the technical reason why a class function is called a method; perhaps another user could enlighten us
When I first started programming I was under the impression that functions were a neat way to encapsulate scripts and return a single value whereas methods encapsulate scripts but do not return values.
Try searching for “PHP delusions” because the site has very sound advice regarding PHP, MySQL, PDO, etc
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.