Forums / Bug Reports / [Fixed v1.5.1] PHP Warning: strlen() expects parameter 1 to be string

[Fixed v1.5.1] PHP Warning: strlen() expects parameter 1 to be string

Locked

Views: 25,779

Results 21 to 40 of 43
This thread is locked. New replies are disabled.
17 Oct 2011, 1:58 PM
#21
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,876
Plugin Contributions:
7

[Fixed v1.5.1] PHP Warning: strlen() expects parameter 1 to be string

Did you apply the modification suggested by DrByte?> just got a new debug** using modified code as above**:yes, I am using the modified code.

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

18 Oct 2011, 5:02 PM
#22
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,857
Plugin Contributions:
18

Re: [Fixed v1.5.1] 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.

Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.
Zen Cart Certified hosting at myZenCartHost.com

18 Oct 2011, 8:12 PM
#23
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,876
Plugin Contributions:
7

Re: [Fixed v1.5.1] PHP Warning: strlen() expects parameter 1 to be string

Thanks for the interest.

This is exactly what I have in the live shop 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) ) {

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

26 Oct 2011, 6:09 PM
#24
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,876
Plugin Contributions:
7

Re: [Fixed v1.5.1] 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?

[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
)

)

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

26 Oct 2011, 6:17 PM
#25
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,857
Plugin Contributions:
18

Re: [Fixed v1.5.1] 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.

Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.
Zen Cart Certified hosting at myZenCartHost.com

29 Oct 2011, 12:37 PM
#26
wirefram avatar

wirefram

New Zenner

Join Date:
Apr 2011
Posts:
95
Plugin Contributions:
0

Re: [Fixed v1.5.1] 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:

**2nd market domain names for sale **
dot com only !
http://www.ventesites.com

23 Nov 2011, 2:14 PM
#27
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,876
Plugin Contributions:
7

Re: [Fixed v1.5.1] 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).

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

14 Dec 2011, 11:18 PM
#28
aureanus avatar

aureanus

New Zenner

Join Date:
Dec 2011
Posts:
2
Plugin Contributions:
0

Re: [Fixed v1.5.1] 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:

 
    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

 
    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

15 Dec 2011, 4:52 AM
#29
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,876
Plugin Contributions:
7

Re: [Fixed v1.5.1] PHP Warning: strlen() expects parameter 1 to be string

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!

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

15 Dec 2011, 8:01 AM
#30
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: [Fixed v1.5.1] PHP Warning: strlen() expects parameter 1 to be string

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.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

15 Dec 2011, 11:36 AM
#31
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,876
Plugin Contributions:
7

Re: [Fixed v1.5.1] PHP Warning: strlen() expects parameter 1 to be string

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.

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

16 Dec 2011, 10:51 PM
#32
aureanus avatar

aureanus

New Zenner

Join Date:
Dec 2011
Posts:
2
Plugin Contributions:
0

Re: [Fixed v1.5.1] PHP Warning: strlen() expects parameter 1 to be string

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

 

$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) ) { 
16 Dec 2011, 11:25 PM
#33
luslo avatar

luslo

New Zenner

Join Date:
Nov 2011
Posts:
1
Plugin Contributions:
0

Re: [Fixed v1.5.1] PHP Warning: strlen() expects parameter 1 to be string

torvista:

Thanks for the interest.

This is exactly what I have in the live shop 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.
17 Dec 2011, 9:08 AM
#34
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,876
Plugin Contributions:
7

Re: [Fixed v1.5.1] PHP Warning: strlen() expects parameter 1 to be string

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:

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

17 Dec 2011, 9:02 PM
#35
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: [Fixed v1.5.1] 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.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

17 Dec 2011, 9:21 PM
#36
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,876
Plugin Contributions:
7

Re: [Fixed v1.5.1] 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!

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.

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

31 Jan 2012, 9:45 PM
#37
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,876
Plugin Contributions:
7

Re: [Fixed v1.5.1] PHP Warning: strlen() expects parameter 1 to be string

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

 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.

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

17 Apr 2012, 8:54 PM
#38
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,876
Plugin Contributions:
7

Re: [Fixed v1.5.1] 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.

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

17 Apr 2012, 11:00 PM
#39
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: [Fixed v1.5.1] 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.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

18 Apr 2012, 9:38 AM
#40
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,876
Plugin Contributions:
7

Re: [Fixed v1.5.1] 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

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...