FIXING AND SUPPRESING PHP ERRORS - May 25th, 2017
|
Starting with CMSB V.2.64, finding PHP errors on a site has become much easier thanks to the addition of a global error logging section.
Many of these errors have gone (happily) undetected by both you and your client.
This will be a growing list of fixes for the most commonly found errors. If you have any additions or corrections, please share them with me via the contact page, or on the CMSB Forum in post:
https://www.interactivetools.com/forum/forum-posts.php?postNum=2236347
Here's a few to start
***NOTE: Based on personal experience, make sure that your page works as planned after you attempt to suppress errors. Otherwise you may be in for some unexpected surprises.***
"Invalid argument supplied for foreach()" in website membership, uncomment the array it was referencing at the top and just blanked out the fields like this:
//$GLOBALS['WEBSITE_LOGIN_REQUIRED_FIELDS'] = array('agree_tos','agree_legal'); $GLOBALS['WEBSITE_LOGIN_REQUIRED_FIELDS'] = array();
Another way to do that is put an if around the foreach: if ($array) { foreach ($array as $item) { // ... } }
If you get an undefined or unknown index in an array, you can add an @ in front of the arrays:
if (!@$higher_exceptions[$word]) {$word = strtolower($word);} if ((!@$lower_exceptions[$word]) || ($word == $firstElement) || ($word == $lastElement) ) {$word = ucfirst($word);}
Same for split: $words = @split(" ", $instruction);
In general, you can add the error-suppression operator @ in front of @php_functions(), @$variables and @$array['lookups'].
If you're using the not operator, !, as in !$your_variable, you should put the @ after the ! operator, like this: !@$your_variable.
Dave Edis, at Interactive Tool explains:
@!$_REQUEST['save']. processes from right to left:
$_REQUEST['save'] - check for value of array element with key of 'save', If it's not defined display a warning @ If a warning was produced by the last operation don't show it ! (NOT) check if the last returned value was boolean false (and an undefined array index would return null which evaluates as false)
VS:
$_REQUEST['save'] - check for value of array element with key of 'save', If it's not defined display a warning ! (NOT) check if the last returned value was boolean false (and an undefined array index would return null which evaluates as false) @ If a warning was produced by the last operation don't show it (but this applies to ! now).
You can also use the @ in <?php if(@isset($_REQUEST['submit_count'])
Another one that came up is: _WARNING: session_start(): Cannot send session cookie - headers already sent /my_path_to_/cmsAdmin/lib/database_functions.php (line 762) http://
To which Dave Edis responded:
That session one is one we'd want to know about normally! But in this case we've patched it for the next release (2.65?). Just add a @
@session_start(); // hide error: E_WARNING: session_start(): Cannot send session cache limiter - headers already sent
Another save by Dave...
If you're getting this type of error in an older version of the autobackup plugin:
E_WARNING: unlink(/your_server_path/cmsAdmin/data/backups/your_backup-v2.64-daily-Mon.sql.php): No such file or directory /your_server_path/cmsAdmin/plugins/autoBackup.php (line 71)
According to the Master...
For autobackup you can either update to the new version 1.04 (which has @ if front of unlink) or you can just add @ in from of the unlink's. It's likely because two instances of the backup script are running and one erased the file before the second one got to it. Note that if you upgrade the new autobackup script does require a cron.php running
|
The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact
Interactive Tools for information on the downloading of the software or the purchasing of licenses.