Jump to content

[solved] Problem with $pages->get() and PHP8


psy
 Share

Recommended Posts

It worked before and now not ?

The web server was recently upgraded to PHP8 and I know PHP8 is much stricter on argument typing than previous PHP versions, and this blip resulted in a Server 500 error:

2022-11-16 14:56:21	guest	https://xxxxxxx.com/api/	Fatal Error:  Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, string given in /home/xxxxxxx/public_html/wire/core/PagesLoader.php:845

The code was a 'page get' selector request in an ajax call. It all worked before the PHP update and I'm sure there are others using $pages->get() without issues on PHP8.

$pages->get("id=". $sanitizer->int($data->pid))

I also tried it without the "id=".  I think the problem is more that $options is a string in the line in the PagesLoader.php:

<?php
$options = count($options) ? array_merge($defaults, $options) : $defaults;

Any ideas on how to fix?

Thanks, psy

Solution

Changed line 845 in PagesLoader.php to confirm $options is an array and the site worked again.

		$options = is_array($options) && count($options) ? array_merge($defaults, $options) : $defaults;

 

Edited by psy
Problem solved
Link to comment
Share on other sites

@DV-JF it was running 3.0.200 and I upgraded to the latest dev 3.0.207

I also changed line 845 in PagesLoader.php to confirm if $options is an array:

		$options = is_array($options) && count($options) ? array_merge($defaults, $options) : $defaults;

Switched the site back to PHP8 and it's working again.

@ryan fyi

  • Like 1
Link to comment
Share on other sites

  • psy changed the title to [solved] Problem with $pages->get() and PHP8

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...