Skip to content

The "defined" method not scoped with class constants #667

New issue

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

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

Already on GitHub? # to your account

Closed
alexander-schranz opened this issue Mar 11, 2022 · 4 comments · Fixed by #745
Closed

The "defined" method not scoped with class constants #667

alexander-schranz opened this issue Mar 11, 2022 · 4 comments · Fixed by #745
Labels

Comments

@alexander-schranz
Copy link
Contributor

alexander-schranz commented Mar 11, 2022

Bug report

Question Answer
PHP-Scoper version 0.17.0
PHP version 8.0.5
Platform with version MacOS
Github Repo -

I try to scope a package which uses the guzzlehttp and this snippet of it with defined:

function guzzle_major_version()
{
    static $cache = null;
    if (null !== $cache) {
        return $cache;
    }
    if (\defined('\\GuzzleHttp\\ClientInterface::VERSION')) { // should have Legacy prefix
        $version = (string) ClientInterface::VERSION;
        if ($version[0] === '6') {
            return $cache = 6;
        }
        if ($version[0] === '5') {
            return $cache = 5;
        }
    } elseif (\defined('\\GuzzleHttp\\ClientInterface::MAJOR_VERSION')) { // should have Legacy prefix
        return $cache = ClientInterface::MAJOR_VERSION;
    }
    throw new \RuntimeException('Unable to determine what Guzzle version is installed.');
}

Is not correctly being replaced, by the prefix.

scoper.inc.php
<?php

declare(strict_types=1);

// scoper.inc.php

use Isolated\Symfony\Component\Finder\Finder;

return [
   'prefix' => 'Legacy',
   'finders' => [
       Finder::create()->files()->in('legacy'),
   ],
   'expose-namespaces' => [
       'Finder',
   ],
];

I found #281 / #283 so nut sure why this is not working 🤔

Reproducer: #668

alexander-schranz added a commit to alexander-schranz/php-scoper that referenced this issue Mar 11, 2022
@alexander-schranz alexander-schranz changed the title The "defined" method not correcty scoped The "defined" method not scoped with class constants Mar 15, 2022
@theofidry
Copy link
Member

defined() is definitely handled and used quite a lot. I was however not aware you could use it to refer to a class-like constant so it could be that it's not working as expected in this case.

Meanwhile if this is a blocker for you I recommend you to fix it manually via a patcher.

@theofidry theofidry added the bug label Mar 15, 2022
@alexander-schranz
Copy link
Contributor Author

@theofidry Thx for response. I was also not aware of that 😄 . A patcher sounds like a great idea as current workaround thank you!

@theofidry
Copy link
Member

I think I found the issue :)

@theofidry
Copy link
Member

Closed by #745

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

Successfully merging a pull request may close this issue.

2 participants