• Home
  • Integrations
  • SDKs
  • Guides
  • API docs
    No results for ""
    EXPAND ALL

    EDIT ON GITHUB

    PHP SDK 3.x to 4.0 migration guide

    Read time: 2 minutes
    Last edited: May 13, 2022

    Overview

    This topic explains how to adapt code that currently uses a 3.x version of the PHP server-side SDK to use version 4.0 or later.

    Before you migrate to 4.0, update to the latest 3.x version. To learn more about updating to the latest 3.x version, visit the SDK's GitHub repository.

    Identifying PHP versions for the 4.0 SDK

    The 4.x version of the SDK is compatible with PHP versions 7.3 and higher. LaunchDarkly no longer supports older PHP versions, as is documented in the End of Life policy.

    Understanding type annotations

    Modern versions of PHP support type declarations. The 4.x SDK includes argument type declarations and return type declarations for all public methods.

    This means that you will get a TypeError at runtime if your code does any of these things:

    • Passing an incorrect type of data to an SDK method.
    • Passing a null value where a null was not allowed.
    • Trying to use the return value of an SDK method as an incorrect type.

    These mistakes may have caused errors in the 3.x SDK, but in most cases, they would have happened later in the SDK code and would have been harder to diagnose. With a TypeError, it is easier to identify the problem.

    To detect type errors before runtime, you can use a static analysis tool such as Psalm. The SDK's build process now uses Psalm to avoid incorrect type usage in its code.

    The SDK does not use the mixed type in its type declarations, because mixed is only supported in PHP 8.x. It does use mixed in documentation comment tags for use by Psalm.

    Understanding changes to database integrations

    Previously, the launchdarkly/server-sdk package included optional database integrations for Redis, DynamoDB, and Consul.

    These have been moved to separate packages:

    Each of these packages declares the dependencies it needs, such as the predis package for launchdarkly/server-sdk-redis-predis.

    Therefore, if you were previously using one of these integrations, you should change your composer.json file as follows:

    • For LaunchDarkly\Integrations\Redis: add a dependency on launchdarkly/server-sdk-redis-predis version 1.*, and remove your dependency on predis/predis unless you are using it for other purposes.
    • For LaunchDarkly\Integrations\PHPRedis: add a dependency on launchdarkly/server-sdk-redis-phpredis version 1.*.
    • For LaunchDarkly\Integrations\DynamoDB: add a dependency on launchdarkly/server-sdk-dynamodb version 1.*, and remove your dependency on aws/aws-sdk-php unless you are using it for other purposes.
    • For LaunchDarkly\Integrations\Consul: add a dependency on launchdarkly/server-sdk-consul version 1.*, and remove your dependency on sensiolabs/consul-php-sdk unless you are using it for other purposes.

    Understanding what was deprecated

    All types and methods that were marked as deprecated in the last 3.x release have been removed from the 4.0 release. If you were using these with a recent version previously, you should already have received deprecation warnings at build time or runtime, with suggestions about their recommended replacements.

    Many types that were not intended for use by applications have been moved out of the main namespace into the Impl namespace. These classes were never documented and had already been marked with an @internal tag to indicate that they were for the SDK's internal use. Anything within Impl is subject to change at any time and should not be referenced in your code.

    Other types are no longer in the main namespace because there is a replacement for them in the Integrations namespace. Those replacements already existed in the 3.x SDK, but now they are the only way to use these features. Here are the old types, and their replacements: