Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8 Problems #29

Open
icgdoug opened this issue Dec 20, 2021 · 9 comments
Open

PHP 8 Problems #29

icgdoug opened this issue Dec 20, 2021 · 9 comments

Comments

@icgdoug
Copy link

icgdoug commented Dec 20, 2021

We are constantly getting errors when using PHP 8 with the plugin.

An error of type E_ERROR was caused in line 42 of the file /httpdocs/wp-content/plugins/official-facebook-pixel/vendor/facebook/php-business-sdk/src/FacebookAds/Object/ServerSide/Normalizer.php. Error message: Uncaught TypeError: strlen(): Argument #1 ($string) must be of type string, array given in httpdocs/wp-content/plugins/official-facebook-pixel/vendor/facebook/php-business-sdk/src/FacebookAds/Object/ServerSide/Normalizer.php:42

The issue resolves by downgrading to a lower version of PHP

@scottbuscemi
Copy link

I tried contacting their support about this issue but they don't seem to understand the problem. This plugin isn't PHP 8 compatible and I can't see how to request for its update.

@icgdoug
Copy link
Author

icgdoug commented Jan 4, 2022

Hi @scottbuscemi yes I've tried as well but they don't seem to recognise support queries for the plugin on the core Facebook Business service.

Does anyone have any other contact methods?

@robwoodgate
Copy link

robwoodgate commented Jan 6, 2022

The issue, as the error suggests, is that the Normalizer::normalize($field, $data) method is expecting the $data parameter to sent in as a string, but the calling class is sending it as an array.

I don't know whether the calling class or the offending method is 'wrong'... however, a quick and dirty fix is as follows.

  1. Open the file: wp-content/plugins/official-facebook-pixel/vendor/facebook/php-business-sdk/src/FacebookAds/Object/ServerSide/Normalizer.php

  2. Find the following section (starting at line 41)

public static function normalize($field, $data) {
    if ($data == null || strlen($data) == 0) {
      return null;
    }
  1. Change it to the following (note the addition of the lines of code between the // START and // END comments):
public static function normalize($field, $data) {

    // START: Quick fix to avoid PHP Warning that breaks PHP8
    // Issue: Some data is sent as an array, but this method expects string
    if (is_array($data)) {
        $data = $data[0];
    }
    // END: Quick fix to avoid PHP Warning that breaks PHP8

    if ($data == null || strlen($data) == 0) {
      return null;
    }

That's it... what the code snippet does is check if the $data parameter is an array, and if it is, just grabs the first item.

Cheers
Rob

Ps - This is a temporary solution - the proper fix is for Facebook to update / fix the php-business-sdk and re-release the plugin to WordPress :)

@Invader444
Copy link

The issue is actually in the plugin code, not the business sdk. It was probably introduced in this commit; I have opened PR #32 with the fix.

@robwoodgate
Copy link

robwoodgate commented Mar 10, 2022 via email

@Invader444
Copy link

Actually, at the time the commit I referenced above was written, the business SDK didn't differentiate between single values and arrays so it would have worked. Starting at version 10.0.1 of the business SDK, they made the distinction between single values and arrays... so this commit would have introduced the bug (when they started using v10.0.1+ of the business SDK).

So it's only been broken since August 2021 (in GitHub anyway... not sure when that code made it to the WordPress repo for general distribution). Still, having this around for seven months is pretty bad; they clearly don't pay a lot of attention to this product... 👎

@maximejobin
Copy link

Even with the latest update (3.0.8), this bug still exists. I do not see any active development to fix issues here, unfortunately.

@Invader444
Copy link

On the bright side, the fix PR finally got merged...

1 year and 7 months for this bug (and counting since it still isn't released to wordpress.org) 🙄

@burtonrhodes
Copy link

Just FYI, this issue has been officially resolved in version 3.0.9:

2023-04-03 version 3.0.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants