Skip to content

Deprecated.php: unconditional define() causes fatal error when REQUESTS_SILENCE_PSR0_DEPRECATIONS is already defined #415

Description

@N-M

Problem

Deprecated.php defines REQUESTS_SILENCE_PSR0_DEPRECATIONS unconditionally:

define("REQUESTS_SILENCE_PSR0_DEPRECATIONS", true);

If another package or the host application (e.g. WordPress core, which defines this constant in its bundled Requests library) has already defined it before this file is loaded, PHP throws a fatal error:

PHP Fatal error: Constant REQUESTS_SILENCE_PSR0_DEPRECATIONS already defined

Note that Razorpay.php in the same package already guards the constant correctly:

if (!defined('REQUESTS_SILENCE_PSR0_DEPRECATIONS'))
    define('REQUESTS_SILENCE_PSR0_DEPRECATIONS', true);

Deprecated.php should follow the same pattern.

Suggested fix

if (!defined('REQUESTS_SILENCE_PSR0_DEPRECATIONS')) define("REQUESTS_SILENCE_PSR0_DEPRECATIONS", true);

Environment

Reproduced when using razorpay/razorpay-php inside a WordPress plugin. WordPress core defines REQUESTS_SILENCE_PSR0_DEPRECATIONS before the plugin's Composer autoloader runs, causing Deprecated.php to collide on load.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    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