Welcome to the Cumulus Support forum.

Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024

Cumulus MX V4 beta test release 4.0.0 (build 4017) - 17 March 2024

Legacy Cumulus 1 release v1.9.4 (build 1099) - 28 November 2014 (a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)

Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki

A few PHP issues

Other discussion about creating web sites for Cumulus that doesn't have a specific subforum

Moderator: daj

Post Reply
Mapantz
Posts: 1774
Joined: Sat 17 Dec 2011 11:55 am
Weather Station: Davis Vantage Pro2
Operating System: Windows 11 x64
Location: Dorset - UK
Contact:

A few PHP issues

Post by Mapantz »

Merry Crimbo everyone!

I decided to purchase WXSIM a few days ago - loving it!

I'm in the process of adding some scripts to my site that take advantage of it. However, a couple of scripts are based around an older version of PHP, and I use 7.2. I have spent some of the day fixing hundred of minor things, but a couple have stumped me.

I did do some searching but as my knowledge is limited, I couldn't fix it.

The three lines have all of the same warnings:

Code: Select all

PHP Warning:  count(): Parameter must be an array or an object that implements Countable in

Line1:

Code: Select all

 }elseif(count($icno12h)==1){
Line2:

Code: Select all

  if(count($icno12h)>1){
Line3:

Code: Select all

 if(count($tsdescs)>0){$tsdesc=max($tsdescs);}else{$tsdesc=$tsdescs;}
I have also found this one:

Code: Select all

PHP Warning:  preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in
Which corresponds to:

Code: Select all

  $fixedtxt = preg_replace('!\.\s+([a-z])!es',"'.  ' . strtoupper('\\1')",$fixedtxt);
If I can draw any PHP's guru's away from prepping their xmas turkey's, that'd be fantastic! :)
Image
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: A few PHP issues

Post by beteljuice »

Have the arrays been declared in the first place ?
Image
......................Imagine, what you will KNOW tomorrow !
User avatar
saratogaWX
Posts: 1170
Joined: Wed 06 May 2009 5:02 am
Weather Station: Davis Vantage Pro Plus
Operating System: Windows 10 Professional
Location: Saratoga, CA, USA
Contact:

Re: A few PHP issues

Post by saratogaWX »

Which script?
Mapantz
Posts: 1774
Joined: Sat 17 Dec 2011 11:55 am
Weather Station: Davis Vantage Pro2
Operating System: Windows 11 x64
Location: Dorset - UK
Contact:

Re: A few PHP issues

Post by Mapantz »

saratogaWX wrote: Mon 24 Dec 2018 9:53 pm Which script?
Henkka's from nordic weather.

I spoke to him briefly about it and he said about it being designed for php5.*
So, I decided to try and fix a ton of minor errors by myself - didn't do too badly, just have those four left.
beteljuice wrote: Mon 24 Dec 2018 9:33 pm Have the arrays been declared in the first place ?
Line 369

if(count($icno12h)>1){

Line 377:

}elseif(count($icno12h)==1){

Line 738:

if(count($tsdescs)>0){$tsdesc=max($tsdescs);}else{$tsdesc=$tsdescs;}

File below:
data.php.txt
The other script:

Line 961:

$fixedtxt = preg_replace('!\.\s+([a-z])!es',"'. ' . strtoupper('\\1')",$fixedtxt);

File below:
wxall.plaintext.php.txt
You do not have the required permissions to view the files attached to this post.
Image
User avatar
saratogaWX
Posts: 1170
Joined: Wed 06 May 2009 5:02 am
Weather Station: Davis Vantage Pro Plus
Operating System: Windows 10 Professional
Location: Saratoga, CA, USA
Contact:

Re: A few PHP issues

Post by saratogaWX »

The array as wrong type errors should be fixable by initializing the variable to array();

The

Code: Select all

$fixedtxt = preg_replace('!\.\s+([a-z])!es',"'. ' . strtoupper('\\1')",$fixedtxt);
is a bit more complex.. the /e modifier was deprecated in PHP 5.5.

Try using

Code: Select all

if(!function_exists('wxsim_repl')) {
  function wxsim_repl($m) {
    return ('.  ' . strtoupper($m[1])); // function does what deprecated /e did for us before
   }
}

$fixedtxt = preg_replace_callback('!\.\s+([a-z])!s','wxsim_repl',$fixedtxt);
Mapantz
Posts: 1774
Joined: Sat 17 Dec 2011 11:55 am
Weather Station: Davis Vantage Pro2
Operating System: Windows 11 x64
Location: Dorset - UK
Contact:

Re: A few PHP issues

Post by Mapantz »

saratogaWX wrote: Mon 24 Dec 2018 10:43 pm The array as wrong type errors should be fixable by initializing the variable to array();

The

Code: Select all

$fixedtxt = preg_replace('!\.\s+([a-z])!es',"'. ' . strtoupper('\\1')",$fixedtxt);
is a bit more complex.. the /e modifier was deprecated in PHP 5.5.

Try using

Code: Select all

if(!function_exists('wxsim_repl')) {
  function wxsim_repl($m) {
    return ('.  ' . strtoupper($m[1])); // function does what deprecated /e did for us before
   }
}

$fixedtxt = preg_replace_callback('!\.\s+([a-z])!s','wxsim_repl',$fixedtxt);
That nailed that one Ken! Thank you. :)
Image
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: A few PHP issues

Post by beteljuice »

Try this @ line #44

Code: Select all

    $temps=$clouds=$wspds=$wdirs=$pops=$tsrisks=$tsdescs=$ics12h=$icno12h=$ics12hna=$icno12hna=array();
No promises it won't break something :o
Image
......................Imagine, what you will KNOW tomorrow !
Mapantz
Posts: 1774
Joined: Sat 17 Dec 2011 11:55 am
Weather Station: Davis Vantage Pro2
Operating System: Windows 11 x64
Location: Dorset - UK
Contact:

Re: A few PHP issues

Post by Mapantz »

beteljuice wrote: Tue 25 Dec 2018 2:02 am Try this @ line #44

Code: Select all

    $temps=$clouds=$wspds=$wdirs=$pops=$tsrisks=$tsdescs=$ics12h=$icno12h=$ics12hna=$icno12hna=array();
No promises it won't break something :o
Hi beteljuice.

Do you mean to just add it at line 44? Or replace something at line 44?

I added it, nothing breaks, but the same error still appears.
Image
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: A few PHP issues

Post by beteljuice »

Just add ...
but the same error still appears
Do ALL errors still occur or are you down to one ?
Image
......................Imagine, what you will KNOW tomorrow !
Mapantz
Posts: 1774
Joined: Sat 17 Dec 2011 11:55 am
Weather Station: Davis Vantage Pro2
Operating System: Windows 11 x64
Location: Dorset - UK
Contact:

Re: A few PHP issues

Post by Mapantz »

beteljuice wrote: Tue 25 Dec 2018 10:38 pm Just add ...
but the same error still appears
Do ALL errors still occur or are you down to one ?
Just down to one, beteljuice.

PHP Warning: count(): Parameter must be an array or an object that implements Countable on line 738

Code: Select all

if(count($tsdescs)>0){$tsdesc=max($tsdescs);}else{$tsdesc=$tsdescs;}
Image
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: A few PHP issues

Post by beteljuice »

OK. It looks like a PHP 7.2 quiet change I hadn't picked up on.

I think count is returning the error because the content is null even though the array it's checking HAS been 'initialised'.

Try this as a replacement to #738

Code: Select all

if(!empty($tsdescs)) {
     if(count($tsdescs)>0){$tsdesc=max($tsdescs);}else{$tsdesc=$tsdescs;}
}
If that fixes things, I must remember it for future 'gotchas' !
Image
......................Imagine, what you will KNOW tomorrow !
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: A few PHP issues

Post by beteljuice »

Knock, knock ......

Any result Mapantz ?

... and if so, what was the solution ?
Image
......................Imagine, what you will KNOW tomorrow !
Mapantz
Posts: 1774
Joined: Sat 17 Dec 2011 11:55 am
Weather Station: Davis Vantage Pro2
Operating System: Windows 11 x64
Location: Dorset - UK
Contact:

Re: A few PHP issues

Post by Mapantz »

Hi beteljuice

Sorry my friend, I do apologise! I have been quite busy! I'll check it out in an hour or two and i will get back to you. :)
Image
User avatar
ConligWX
Posts: 1570
Joined: Mon 19 May 2014 10:45 pm
Weather Station: Davis vPro2+ w/DFARS + AirLink
Operating System: Ubuntu 22.04 LTS
Location: Bangor, NI
Contact:

Re: A few PHP issues

Post by ConligWX »

no doubt we shall have some fun when we start changing to php 7.3 too. :lol:
Regards Simon

https://www.conligwx.org - @conligwx
Davis Vantage Pro2 Plus with Daytime FARS • WeatherLink Live • Davis AirLink • PurpleAir •

Image
Post Reply