Skip to content

Scope "ext" classes if they're installed with composer too #1109

@kkmuffme

Description

@kkmuffme

Bug report

Question Answer
PHP-Scoper version 0.18.14
PHP version 8.3.0
{
    "name": "foo",
    "type": "library",
    "homepage": "foo.com",
    "authors": [
        {
            "name": "foo"
        }
    ],
    "minimum-stability": "stable",
    "require": {
        "php": "~8.1.0 || ~8.2.0 || ~8.3.0",
        "googleads/google-ads-php": ">=22"
    },
    "config": {
        "optimize-autoloader": true,
        "classmap-authoritative": true,
        "platform": {
            "php": "8.1.0",
            "ext-protobuf": false,
            "ext-grpc": false
        },
        "platform-check": true
    }
}

default scoper config

On my machine where I run scoper, I have grpc (and protobuf) installed for PHP - since I set it to false for the platform, composer (correctly) installed both packages.

However scoper somehow created a weird mix of exposed and scoped that will lead to fatals.
e.g. vendor\grpc\grpc\src\lib\BaseStub.php has a scoped namespace (correct): namespace Foo\Grpc;
It also correctly scoped the code in it, e.g.

if (!\method_exists('Foo\\Grpc\\ChannelCredentials', 'isDefaultRootsPemSet') || ...

However in vendor\google\gax\src\Transport\GrpcTransport.php all use statements are correctly scoped, except:

use Grpc\Channel;
use Grpc\ChannelCredentials;

I guess this happens bc scoper sees that these classes are available in PHP natively and treats them as exposed (just like use Exception; which is obviously correct)

Possible solutions:

  1. check composer platform for ext and if false, don't automatically expose
  2. if the class exists in composer packages to be scoped too, then also scope it, even if it exists natively on the system

I guess 2 is easier?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions