-
[Fixed v1.5.1] PHP Warning: strlen() expects parameter 1 to be string
This continues to mess with my brain (an admittedly easy task!).
Several of our sites are getting
Quote:
PHP Warning: strlen() expects parameter 1 to be string, array given in /home/site_name/public_html/includes/functions/functions_general.php on line 152
Commonalities are minimal other than all sites effected are 1.3.9h and all debug files to the cache directory are timestamped at the conclusion of an order. All have IH2 and Fual Slimbox. Some have captcha and newsletter subscription, but we get the error on sites with neither, just one, or both of those mods.:dontgetit
Whether the site is using AIM, PayPal, Ceon's offline, or some other payment module seems to make no difference. AND, only occasionally does any site throw this error. One site has 25+ orders this month with a mixture of PayPal and AIM. Only two orders (one for each) has thrown the error.
We have checked and re-checked for current PayPal and AIM files along with other payment mods.
No changes have been made to customer database settings or files gathering/forwarding customer data.
If it would JUST BREAK already, we could fix it.:frusty:
Any suggestions of other things we might check would be GREATLY appreciated.
-
Re: PHP Warning: strlen() expects parameter 1 to be string
Not that I can assist but you left out php ver & mysql ver
-
Re: PHP Warning: strlen() expects parameter 1 to be string
Try inserting above l 152:
if (is_null($value)) continue;
-
Re: PHP Warning: strlen() expects parameter 1 to be string
Should read my sig, huh?:blush:
PHP 5.3.3 MySQL 5.0.67 for all.
-
Re: PHP Warning: strlen() expects parameter 1 to be string
Did you try the suggestion from swguy?
Looks to be a workaround, but there must be a root cause as I have never seen this error
-
Re: PHP Warning: strlen() expects parameter 1 to be string
definitely a work around and will take days or weeks to see if it works, but will stick it in a couple of the more active sites.
I've come close to finding similar items in the forum, but just when you think you might have found the answer.......:lamo:
-
Re: PHP Warning: strlen() expects parameter 1 to be string
Narrowed down to something coming from authorize.net in completing a purchase. Error was on the 13th and it's coming 25 seconds after the purchase is logged.
Odd that it doesn't happen on the 15th. Only difference I can see between the two orders is that the 15th has a different shipping from billing.
:frusty:
-
Re: PHP Warning: strlen() expects parameter 1 to be string
If the warning is triggering on strlen($value), try moving that to the end of the testing list so other conditions are parsed first.
The strlen() function wants a string, and if one of the keys holds an array, that would probably be the cause. What could the 'error' consist of?
&& ($key != 'error')
It would cease processing if $key did equal 'error'.
PHP Code:
if ( (strlen($value) > 0) && ($key != 'main_page') && ($key != zen_session_name()) && ($key != 'error') && (!in_array($key, $exclude_array)) && ($key != 'x') && ($key != 'y') ) {
-
Re: PHP Warning: strlen() expects parameter 1 to be string
did anyone find out what to do to solve this php warming?
I am having the same problem....
:(
-
Re: PHP Warning: strlen() expects parameter 1 to be string
Still rearing it's ugly head from time to time but have not aggressively pursued it as I can't seem to find anything that dies because of it.:dontgetit
Are you actually able to determine anything that is not working due to this error?
-
Re: PHP Warning: strlen() expects parameter 1 to be string
Quote:
Originally Posted by
dbltoe
Any suggestions of other things we might check would be GREATLY appreciated.
From a diagnostics perspective, you could try to capture information about whatever the offending component is by inserting this line at line 152:
Code:
if (is_array($value)) trigger_error('GET param found to be array: ' . print_r($value, true) . ' --- contents of GET: ' . print_r($_GET, true));
Depending on your PHP configuration, that should dump the offending details into the myDebug-xxxxx.log logs, as per https://www.zen-cart.com/tutorials/index.php?article=82
DO NOT TRY THIS IF YOU ARE USING A VERSION OLDER THAN v1.3.9a !!!!!!!!!
-
Re: PHP Warning: strlen() expects parameter 1 to be string
I got a debug file with this identical error today.
First error ever on the live shop.
Order confirmed at 15:19:58 (using 4b payment module, Spain)
Debug Warning at 15:20:24
ZC 1.39h
PHP Version: 5.3.8 (Zend: 2.3.0)
PHP Safe Mode: Off
PHP Memory Limit: 128M
Database: MySQL 5.0.92-community-log
HTTP Server: Apache
Main mods, IH2, Ceon Advanced Shipper, 4b payment module...a long list.
I've put in the suggested debug code.
-
Re: PHP Warning: strlen() expects parameter 1 to be string
Ok, I got two of these today.
1)
Order at 10:53:12
Debug at 10:54:01
Payment - Moneyorder
Shipping - Advanced Shipper
Quote:
[06-Oct-2011 10:54:01] PHP Notice: GET param found to be array: Array
(
[0] => 47
)
--- contents of GET: Array
(
[main_page] => index
[action] => notify
[notify] => Array
(
[0] => 47
)
)
in /whatever/includes/functions/functions_general.php on line 152
[06-Oct-2011 10:54:01] PHP Warning: strlen() expects parameter 1 to be string, array given in /whatever/includes/functions/functions_general.php on line 153
2)
Order at 11:48:57
Debug at 11:49:25
Payment - 4b (offsite credit card gateway)
Shipping - Advanced Shipper
Quote:
[06-Oct-2011 11:49:25] PHP Notice: GET param found to be array: Array
(
[0] => 56
)
--- contents of GET: Array
(
[main_page] => index
[action] => notify
[notify] => Array
(
[0] => 56
)
)
in /whatever/includes/functions/functions_general.php on line 152
[06-Oct-2011 11:49:25] PHP Warning: strlen() expects parameter 1 to be string, array given in /whatever/includes/functions/functions_general.php on line 153
I don't find anything I can relate to those numbers 47 and 56 in the order.
So, any more clues I can give you?
Thanks
Steve
-
Re: PHP Warning: strlen() expects parameter 1 to be string
Why are you passing a [notify] in your $_GET in the first place? What addon is doing that, and why?
-
Re: PHP Warning: strlen() expects parameter 1 to be string
Quote:
Why are you passing a [notify] in your $_GET in the first place?
No idea. Nothing I have actually coded myself.
I've done some searching and the only references I can find to notify and get would be in the shopping cart class, for example:
zen_redirect(zen_href_link($_GET['main_page'], zen_get_all_get_params(array('action', 'notify', 'main_page'))));
but this is a stock file and I don't really understand what I'm looking at or for.
Can you suggest more that I can add to the debug info to help locate this? Or a construct I could search for in the code?
-
Re: PHP Warning: strlen() expects parameter 1 to be string
Quote:
Originally Posted by
dbltoe
Still rearing it's ugly head from time to time but have not aggressively pursued it as I can't seem to find anything that dies because of it.:dontgetit
Are you actually able to determine anything that is not working due to this error?
It's only a "PHP Warning", so is not causing any script executions to fail.
Thus, it's a minor issue.
Indeed, thanks to some of torvista's debug data, I've found the cause, and it's an extremely minor issue.
Quote:
Originally Posted by
dbltoe
Several of our sites are getting:
PHP Warning: strlen() expects parameter 1 to be string, array given in /home/site_name/public_html/includes/functions/functions_general.php on line 152
Commonalities are ... all debug files to the cache directory are timestamped at the conclusion of an order.
...
AND, only occasionally does any site throw this error. One site has 25+ orders this month with a mixture of PayPal and AIM. Only two orders (one for each) has thrown the error.
It only occurs at the conclusion of an order because it's specifically triggered only when the user is presented with a list of product-notification choices and they click the submit button on that page to update those choices. (It might also trigger on the account_notifications page if they were to visit there.)
The warning is harmless, and can be safely ignored.
If it's keeping you awake at night, you could move the in_array() condition check to the beginning of the list, by changing the line from
Code:
if ( (strlen($value) > 0) && ($key != 'main_page') && ($key != zen_session_name()) && ($key != 'error') && (!in_array($key, $exclude_array)) && ($key != 'x') && ($key != 'y') ) {
to
Code:
if ( (!in_array($key, $exclude_array)) && (strlen($value) > 0) && ($key != 'main_page') && ($key != zen_session_name()) && ($key != 'error') && ($key != 'x') && ($key != 'y') ) {
-
Re: PHP Warning: strlen() expects parameter 1 to be string
Quote:
If it's keeping you awake at night,
Absolutely!
Thanks for the solution.
-
Re: PHP Warning: strlen() expects parameter 1 to be string
just got a new debug using modified code as above:
Quote:
[17-Oct-2011 09:39:27] PHP Notice: GET param found to be array: Array
(
[0] => 280
)
--- contents of GET: Array
(
[main_page] => index
[action] => notify
[notify] => Array
(
[0] => 280
)
)
in blah..blah/includes/functions/functions_general.php on line 152
-
Re: PHP Warning: strlen() expects parameter 1 to be string
Hi
Did you apply the modification suggested by DrByte?
I did and I no longer have the error, if you check the new beta version 1.5 this modif is applied in the file functions_general.php.
:huh:
-
Re: PHP Warning: strlen() expects parameter 1 to be string
Quote:
Did you apply the modification suggested by DrByte?
Quote:
just got a new debug using modified code as above:
yes, I am using the modified code.
-
Re: PHP Warning: strlen() expects parameter 1 to be string
Steve,
I imagine you already have, but I can't resist asking if you did a winmerge of the old and new just in case.
-
Re: PHP Warning: strlen() expects parameter 1 to be string
Thanks for the interest.
This is exactly what I have in the live shop code:
PHP Code:
while (list($key, $value) = each($_GET)) {
if (is_array($value)) trigger_error('GET param found to be array: ' . print_r($value, true) . ' --- contents of GET: ' . print_r($_GET, true));//steve looking for reason, as per http://www.zen-cart.com/forum/showthread.php?t=176804
//if ( (strlen($value) > 0) && ($key != 'main_page') && ($key != zen_session_name()) && ($key != 'error') && (!in_array($key, $exclude_array)) && ($key != 'x') && ($key != 'y') ) {//steve original line
if ( (!in_array($key, $exclude_array)) && (strlen($value) > 0) && ($key != 'main_page') && ($key != zen_session_name()) && ($key != 'error') && ($key != 'x') && ($key != 'y') ) {//steve this line edited to stop debug error as per http://www.zen-cart.com/forum/showthread.php?p=1070316#post1070316
if ( (SEARCH_ENGINE_FRIENDLY_URLS == 'true') && ($search_engine_safe == true) ) {
-
Re: PHP Warning: strlen() expects parameter 1 to be string
Its odd that this error is not triggered always..?
just got another, the first one since the 17th...
Can I do further testing or just forget it?
Quote:
[25-Oct-2011 23:12:41] PHP Notice: GET param found to be array: Array
(
[0] => 210
)
--- contents of GET: Array
(
[main_page] => index
[action] => notify
[notify] => Array
(
[0] => 210
)
)
-
Re: PHP Warning: strlen() expects parameter 1 to be string
I've never known it to block a sale.
But, as I stated earlier, we've had no problems on any site since changing to the suggested fix.
Sorry I can't be of more help.
-
Re: PHP Warning: strlen() expects parameter 1 to be string
From my experience, this has to do with the "notify" stuff, I am using the Caixa sermepa module and kept having troubles of orders paid but not showing up on my shop.
Do not use the "notify" option, I do not know how your module works but you should be able to disable this.
Won't change anything to the way the program works, you will be notified for each order anyway but your bank will stop trying to send you a mail for this.
In my case, this was where the problem was: the notification url in the module.
Hope this help!
:unsure:
-
Re: PHP Warning: strlen() expects parameter 1 to be string
I get this error across all payment modules.
It could be a week between occurrences so no obvious pattern.
I do use Advanced Shipper so in effect it has the same shipping module in use every time so you could throw mud at that but the developer says not guilty (and is to be trusted).
-
Re: PHP Warning: strlen() expects parameter 1 to be string
The issue is that you are on PHP 5.3 and that changed the way that strlen handles arrays.
Before 5.3 strlen would return the word array for any array - hence feeding a string into the function - from 5.3 it returns NULL instead and strlen fails.
I had the same problem and fixed it by counting the elements in the array instead.
so:
PHP Code:
if ( (!in_array($key, $exclude_array)) && (strlen($value))> 0) && ($key != 'main_page') && ($key != zen_session_name()) && ($key != 'error') && ($key != 'x') && ($key != 'y') ) {//steve this line edited to stop debug error as per http://www.zen-cart.com/forum/showthread.php?p=1070316#post1070316
if ( (SEARCH_ENGINE_FRIENDLY_URLS == 'true') && ($search_engine_safe == true) ) {
would become
PHP Code:
if ( (!in_array($key, $exclude_array)) && (count($value) > 0) && ($key != 'main_page') && ($key != zen_session_name()) && ($key != 'error') && ($key != 'x') && ($key != 'y') ) {
if ( (SEARCH_ENGINE_FRIENDLY_URLS == 'true') && ($search_engine_safe == true) ) {
This assuming that you know you are always getting an array returned. If not then you would need to test if it was an array or a string earlier and set a flag to test against
-
Re: PHP Warning: strlen() expects parameter 1 to be string
Quote:
I had the same problem and fixed it by counting the elements in the array instead.
Thanks for sharing that.
Maybe I'll be able to sleep at night now with no fear of random debugs in the morning!
-
Re: PHP Warning: strlen() expects parameter 1 to be string
Quote:
Originally Posted by
Aureanus
This assuming that you know you are always getting an array returned.
Therein is the problem. It is almost NEVER getting an array. The ONLY time it gets an array is when the product-notifications screen is presented. The zillion other times that the function is used there is no array passed at all.
I submit that your proposed fix is likely to cause the entire function to not return the right results, thus preventing normal operation of the majority of cases where this function is called.
Thus, its NOT SAFE to be used on live sites, unless of course you want to encounter lost sales and poor customer experience while shopping.
-
Re: PHP Warning: strlen() expects parameter 1 to be string
Quote:
Thus, its NOT SAFE to be used on live sites, unless of course you want to encounter lost sales and poor customer experience while shopping.
Assuming that the php version is causing this as Aureanus asserts, I (for one) would be happy to trial a fix...I still get these irritating errors most days.
-
Re: PHP Warning: strlen() expects parameter 1 to be string
Quote:
Originally Posted by
DrByte
Therein is the problem. It is almost NEVER getting an array. The ONLY time it gets an array is when the product-notifications screen is presented. The zillion other times that the function is used there is no array passed at all.
I submit that your proposed fix is likely to cause the entire function to not return the right results, thus preventing normal operation of the majority of cases where this function is called.
Thus, its NOT SAFE to be used on live sites, unless of course you want to encounter lost sales and poor customer experience while shopping.
Fair point, then you just add a test for an array before it
A quick example is below
PHP Code:
$valueStr=0
if (isarray($value)) {
$valueStr=count($value)
}else {
$valueStr=strlen($value)
}
if ( (!in_array($key, $exclude_array)) && $valueStr > 0) && ($key != 'main_page') && ($key != zen_session_name()) && ($key != 'error') && ($key != 'x') && ($key != 'y') ) {
if ( (SEARCH_ENGINE_FRIENDLY_URLS == 'true') && ($search_engine_safe == true) ) {
-
Re: PHP Warning: strlen() expects parameter 1 to be string
Quote:
Originally Posted by
torvista
Thanks for the interest.
This is exactly what I have in the live shop code:
PHP Code:
while (list($key, $value) = each($_GET)) {
if (is_array($value)) trigger_error('GET param found to be array: ' . print_r($value, true) . ' --- contents of GET: ' . print_r($_GET, true));//steve looking for reason, as per http://www.zen-cart.com/forum/showthread.php?t=176804
//if ( (strlen($value) > 0) && ($key != 'main_page') && ($key != zen_session_name()) && ($key != 'error') && (!in_array($key, $exclude_array)) && ($key != 'x') && ($key != 'y') ) {//steve original line
if ( (!in_array($key, $exclude_array)) && (strlen($value) > 0) && ($key != 'main_page') && ($key != zen_session_name()) && ($key != 'error') && ($key != 'x') && ($key != 'y') ) {//steve this line edited to stop debug error as per http://www.zen-cart.com/forum/showthread.php?p=1070316#post1070316
if ( (SEARCH_ENGINE_FRIENDLY_URLS == 'true') && ($search_engine_safe == true) ) {
You just forgot to remove the line containing trigger_error call.
-
Re: PHP Warning: strlen() expects parameter 1 to be string
Quote:
You just forgot to remove the line containing trigger_error call.
You mean the debug was caused by the info, not the original fault!
Doh! :bangin:
-
Re: PHP Warning: strlen() expects parameter 1 to be string
What were the actual messages in the most recently logs? If they weren't text generated by the trigger_error() call you had in your code, then that's not the issue.
-
Re: PHP Warning: strlen() expects parameter 1 to be string
Since the solution posted in post 16, the debug "errors" have indeed just been the output of the error trigger, I just didn't think about it long enough to realise!
Quote:
15-Dec-2011 15:45:48] PHP Notice: GET param found to be array: Array
(
[0] => 136
)
--- contents of GET: Array
(
[main_page] => index
[action] => notify
[notify] => Array
(
[0] => 136
)
)
in blah blah.
-
now in 1.5
after a week running my upgrade to 1.5 I get this error again for the first time:
[31-Jan-2012 20:39:06] PHP Warning: strlen() expects parameter 1 to be string, array given in /home/XXXX/public_html/tienda/includes/functions/functions_general.php on line 152
FYI, from functions_general.php
PHP Code:
function zen_get_all_get_params($exclude_array = '', $search_engine_safe = true) {
if (!is_array($exclude_array)) $exclude_array = array();
$get_url = '';
if (is_array($_GET) && (sizeof($_GET) > 0)) {
reset($_GET);
while (list($key, $value) = each($_GET)) {
if ( (!in_array($key, $exclude_array)) && (strlen($value) > 0) && ($key != 'main_page') && ($key != zen_session_name()) && ($key != 'error') && ($key != 'x') && ($key != 'y') ) {
if ( (SEARCH_ENGINE_FRIENDLY_URLS == 'true') && ($search_engine_safe == true) ) {
// die ('here');
$get_url .= $key . '/' . rawurlencode(stripslashes($value)) . '/';
} else {
$get_url .= zen_sanitize_string($key) . '=' . rawurlencode(stripslashes($value)) . '&';
}
}
}
}
while (strstr($get_url, '&&')) $get_url = str_replace('&&', '&', $get_url);
while (strstr($get_url, '&&')) $get_url = str_replace('&&', '&', $get_url);
return $get_url;
}
Although the cause of the error has already been detailed previously I can confirm its the same:
create a new customer
make a purchase
and after checkout, when presented with the screen and the option to receive product updates (which is already ticked), click on update rather than logout.
-
Re: PHP Warning: strlen() expects parameter 1 to be string
I understand this error "doesn't matter" but as the fix included in 1.5 does not work (at least on my site), how can I stop this debug error being created (on most sales)?
Its the only fault I get and it's an unnecessary maintenance task to have to check and delete them continually.
-
Re: PHP Warning: strlen() expects parameter 1 to be string
Quick and dirty idea: if you and your customers don't actually use the product-notification feature, turn it off and/or delete that form from the checkout-success template, and then none of those inputs will trigger the problems you're complaining about.
-
Re: PHP Warning: strlen() expects parameter 1 to be string
Thanks. I appreciate this is a less than minor problem...and I'll avoid it as you suggest.
Nonetheless I am curious to know why the fix doesn't work (is it just my site?) or does it require a more complicated fix?
I am used to Zen Cart having no errors at all so this stands out.
regards
Steve
-
Re: PHP Warning: strlen() expects parameter 1 to be string
Try this replacement code as the fix:
Code:
function zen_get_all_get_params($exclude_array = '', $search_engine_safe = true) {
if (!is_array($exclude_array)) $exclude_array = array();
$exclude_array = array_merge($exclude_array, array(zen_session_name(), 'main_page', 'error', 'x', 'y'));
$get_url = '';
if (is_array($_GET) && (sizeof($_GET) > 0)) {
reset($_GET);
while (list($key, $value) = each($_GET)) {
if (is_array($value) || in_array($key, $exclude_array)) continue;
if (strlen($value) > 0) {
$get_url .= zen_sanitize_string($key) . '=' . rawurlencode(stripslashes($value)) . '&';
}
}
}
while (strstr($get_url, '&&')) $get_url = str_replace('&&', '&', $get_url);
while (strstr($get_url, '&&')) $get_url = str_replace('&&', '&', $get_url);
return $get_url;
}
Suitable for v1.3.9a thru v1.5.0
Fix included in v1.5.1
-
Re: PHP Warning: strlen() expects parameter 1 to be string
This fix works for me!
thanks
Steve
-
Re: PHP Warning: strlen() expects parameter 1 to be string