Skip to content

v25.0.2: Class "FacebookAds\PII_DATA_TYPE" not found when calling EventRequest::execute() #653

@justpilot

Description

@justpilot

UserData::normalize() fatals: Class "FacebookAds\PII_DATA_TYPE" not found (v25.0.2)

EventRequest::execute() throws Class "FacebookAds\PII_DATA_TYPE" not found whenever the caller did not also call Event::setRequestContext(). Introduced in v25.0.2 by the new facebook/capi-param-builder-php: ^1.3.1 dependency (commit 04cb9b5). v25.0.0 and v25.0.1 are unaffected.

Versions

  • facebook/php-business-sdk 25.0.2
  • facebook/capi-param-builder-php 1.3.1
  • PHP 8.5 / Composer 2.10.1
  • composer install --no-dev --optimize-autoloader

Reproducer

require __DIR__ . '/vendor/autoload.php';

use FacebookAds\Api;
use FacebookAds\Object\ServerSide\{ActionSource, Event, EventRequest, UserData};

Api::init(null, null, 'TOKEN');

$ud = (new UserData())->setEmail('test@example.com');
$ev = (new Event())
    ->setEventName('Lead')
    ->setEventTime(time())
    ->setUserData($ud)
    ->setActionSource(ActionSource::WEBSITE);

(new EventRequest('PIXEL_ID'))->setEvents([$ev])->execute();
PHP Fatal error: Uncaught Error: Class "FacebookAds\PII_DATA_TYPE" not found
  in vendor/facebook/php-business-sdk/src/FacebookAds/Object/ServerSide/UserData.php:936

Adding $ev->setRequestContext($anyContext); before execute() makes the fatal go away.

Cause

UserData.php line 28 imports use FacebookAds\PII_DATA_TYPE; and references PII_DATA_TYPE::EMAIL etc. inside normalize() (lines 936-946).

PII_DATA_TYPE lives in capi-param-builder-php/php/capi-param-builder/src/model/Constants.php under namespace FacebookAds;. The package declares PSR-4 as "FacebookAds\\": "php/capi-param-builder/src/", which means Composer looks for the class at …/src/PII_DATA_TYPE.php and can't find it.

The class only becomes available as a side effect of ParamBuilder.php being autoloaded — it does require_once 'model/Constants.php' at the top. ParamBuilder is instantiated only inside Event::setRequestContext() (Event.php:639). Callers that pre-populate UserData and skip setRequestContext() never trigger that load, and UserData::normalize() fatals on the first PII_DATA_TYPE:: reference.

Fix

Add a files autoload entry to facebook/capi-param-builder-php's composer.json:

"autoload": {
  "psr-4": { "FacebookAds\\": "php/capi-param-builder/src/" },
  "files": [ "php/capi-param-builder/src/model/Constants.php" ]
}

Or move model/Constants.php to a PSR-4-compliant path. Either way FacebookAds\PII_DATA_TYPE becomes loadable without depending on ParamBuilder being instantiated first.

Workaround for users on v25.0.2

"facebook/php-business-sdk": "~25.0.0,<25.0.2"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions