Jump to content

Community

media

PHP 7.2 my other scripts on my site please help???

Recommended Posts

Posted (edited)

For IPB 4 I have upgraded PHP to 7.2 but it broke my other scripts I hope someone can help me on this

Here are 2 problem that I got so far:

Problem 1 ::::::::::::::::::::::::::::::
$count = 0;

$len = count($thename);
While($count < $len )
:::::::::::::::::::::::::::::

[22-Apr-2019 06:23:03 UTC] PHP Warning:  count(): Parameter must be an array or an object that implements Countable in /home/media/public_html/getCards.php on line 120

line 120 is $len = count($thename);

                   
Problem 2::::::::::::::::::::::::
else
{
   $recalc = $lucknumber % 2;
   if($recalc != 0)
   {  
:::::::::::::::::::::::

[22-Apr-2019 06:23:03 UTC] PHP Warning:  A non-numeric value encountered in /home/media/public_html/getCards.php on line 308
                   
line 308 is $recalc = $lucknumber % 2;

Please help?

Thanks

Edited by media

Share this post


Link to post
Share on other sites
Posted (edited)
1 hour ago, Fred Krugger said:

Hi... explicitly try the conversión

e.i.:

$num = "3.14";

$int = (int)$num;

$float = (float)$num;

I thought I asked on here if there were any changes to do to work fine in the latest version and nobody said there was much of anything needing to be done. So we need to be more sure of explicitly casting the types now? I mean I do remember paying more attention to that on my recent app, so maybe I was already using php 7 and noticed it and did all of this... I'll have to look again.

Sometimes it's easy to get mixed up and think they're already the proper types.

Anyway, do you know of any other things that are frequently needing to be changed in old code to be sure it is fine in php 7?

I am going to go look at my php version, because I can't remember. Maybe I tested in it already...

edit: I am on 7.0. So, unless his issue started in a version after that, I have tested enough to have seen if I have an issue. I better go update to 7.1+ now, myself, but 7.2 not yet available on my server.

Edited by Midnight Modding

Share this post


Link to post
Share on other sites
Posted (edited)

I think he's basically saying $thename and $lucknumber aren't cast as integers (or float if they are decimals). So you may need to use something like (int) $thename, for example, to set it as an integer. In his example, above, "3.14" is a string instead of an integer, so he then uses (int) to make it an integer or (float) to make it a decimal.

Edited by Midnight Modding

Share this post


Link to post
Share on other sites
1 hour ago, Matt said:

Just do an is_array() check before the count().

That worked like a charm... Thanks

Any idea about second problem???

Problem 2
::::::::::::::::::::::::::::::::::::::::::
else
{
   $recalc = $lucknumber % 2;
   if($recalc != 0)
   {  
:::::::::::::::::::::::

[22-Apr-2019 06:23:03 UTC] PHP Warning:  A non-numeric value encountered in /home/media/public_html/getCards.php on line 308
                   
line 308 is $recalc = $lucknumber % 2;

 

Share this post


Link to post
Share on other sites

That last error means $lucknumber is not a numeric value (integer or float). Is the variable perhaps not defined, or set to NULL, or something like that? Right before that line you can add

var_dump( $lucknumber );

to see what the value (and type) is. From there, you may find a bug in your code you need to fix, or you may be able to get away with just casting the variable to an integer or float. It's hard to tell you definitively without seeing the rest of the code, however.

Share this post


Link to post
Share on other sites
1 hour ago, bfarber said:

That last error means $lucknumber is not a numeric value (integer or float). Is the variable perhaps not defined, or set to NULL, or something like that? Right before that line you can add


var_dump( $lucknumber );

to see what the value (and type) is. From there, you may find a bug in your code you need to fix, or you may be able to get away with just casting the variable to an integer or float. It's hard to tell you definitively without seeing the rest of the code, however.

Thank you,

That helped... I have added (int) in front of those values solved the problem somehow....
Thanks again...

Share this post


Link to post
Share on other sites
3 hours ago, Matt said:

PHP is rightly getting a little more fussy about type.

It got me being extra sure about that type of thing. I went through looking over everything like that. One thing I had done is when I did a Select on a form and the choices had numeric values, I just moved along, not thinking through that in $form->values it would not be cast as an integer automatically. of course, once you test you end up noticing the issues, so I hopefully caught all of them. Plus I went back through looking, myself, for any that may have slipped through.

13 minutes ago, DSyste said:

@media JI've had this problem too...

Another way to fix this problem is to upgrade to PHP 7.3

PHP 7.3 went back in reverse and doesn't act as strictly about typecasting? Or you mean something else?

Share this post


Link to post
Share on other sites

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...