Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

"Class 'p\\Php80' not found" when use str_starts_with() in PHP7.3 or PHP7.4 #378

Closed
JL2014 opened this issue Dec 1, 2021 · 13 comments
Closed

Comments

@JL2014
Copy link

JL2014 commented Dec 1, 2021

Hi,

In an encrypted environment, in a Windows PHP 7.3 or 7.4 project , we have this error :

production.ERROR: Class 'p\Php80' not found {"exception":"[object] (Error(code: 0): Class 'p\\Php80' not found at .\api\vendor\symfony\polyfill\src\Php80\bootstrap.php:32)
[stacktrace]
#00 ...\api\app\Helpers\Env.php(123): str_starts_with('', '...')
#1 ...\api\app\Helpers\Env.php(142): App\Helpers\Env::decodeEnvPassword('', '...')
#2 ...\api\config\database.php(44): App\Helpers\Env::env_password('...')
#3 ...\api\vendor\laravel\lumen-framework\src\Application.php(688): unknown()
#4 ...\api\vendor\laravel\lumen-framework\src\Application.php(662): Laravel\Lumen\Application->configure('database')
#5 ...\api\vendor\laravel\lumen-framework\src\Application.php(410): Laravel\Lumen\Application->loadComponent('database', Array, 'db')
#6 ...\api\vendor\laravel\framework\src\Illuminate\Container\Container.php(805): Laravel\Lumen\Application->Laravel\Lumen\{closure}(Object(Laravel\Lumen\Application), Array)
#7 ...\api\vendor\laravel\framework\src\Illuminate\Container\Container.php(691): Illuminate\Container\Container->build(Object(Closure))
#8 ...\api\vendor\laravel\framework\src\Illuminate\Container\Container.php(637): Illuminate\Container\Container->resolve('db', Array)
#9 ...\api\vendor\laravel\lumen-framework\src\Application.php(300): Illuminate\Container\Container->make('db', Array)
#10 ...\api\vendor\laravel\lumen-framework\src\Application.php(778): Laravel\Lumen\Application->make('db')
#11 ...\api\bootstrap\app.php(54): Laravel\Lumen\Application->withEloquent()
#12 ...\api\public\index.php(14): unknown()
#13 {main}
"}

Any idea what cause this problem ?

Greetings.

@nicolas-grekas
Copy link
Member

No idea. Can you provide a simple reproducer?

@JL2014
Copy link
Author

JL2014 commented Dec 1, 2021

No idea. Can you provide a simple reproducer?

Unfortunately no because big project in encrypted case ...

@OskarStark
Copy link
Contributor

OskarStark commented Dec 1, 2021

Do you do some special things in composer.json?

@derrabus
Copy link
Member

derrabus commented Dec 1, 2021

Unfortunately no because big project in encrypted case ...

Do you encrypt your vendor folder?

@JL2014
Copy link
Author

JL2014 commented Dec 1, 2021

Hi everyone,

Do you do some special things in composer.json?

there is a "post-autoload-dump" script that modify autoload but nothing linked with this error.

Do you encrypt your vendor folder?

Yes.

In a similar project, we have to downgrade polyfill to 1.19 version to avoid errors.

@nicolas-grekas
Copy link
Member

Can you copy/paste the content of .\api\vendor\symfony\polyfill\src\Php80\bootstrap.php?

@JL2014
Copy link
Author

JL2014 commented Dec 1, 2021

Can you copy/paste the content of .\api\vendor\symfony\polyfill\src\Php80\bootstrap.php?

`<?php

/*

  • This file is part of the Symfony package.
  • (c) Fabien Potencier fabien@symfony.com
  • For the full copyright and license information, please view the LICENSE
  • file that was distributed with this source code.
    */

use Symfony\Polyfill\Php80 as p;

if (\PHP_VERSION_ID >= 80000) {
return;
}

if (!defined('FILTER_VALIDATE_BOOL') && defined('FILTER_VALIDATE_BOOLEAN')) {
define('FILTER_VALIDATE_BOOL', \FILTER_VALIDATE_BOOLEAN);
}

if (!function_exists('fdiv')) {
function fdiv(float $num1, float $num2): float { return p\Php80::fdiv($num1, $num2); }
}
if (!function_exists('preg_last_error_msg')) {
function preg_last_error_msg(): string { return p\Php80::preg_last_error_msg(); }
}
if (!function_exists('str_contains')) {
function str_contains(?string $haystack, ?string $needle): bool { return p\Php80::str_contains($haystack ?? '', $needle ?? ''); }
}
if (!function_exists('str_starts_with')) {
function str_starts_with(?string $haystack, ?string $needle): bool { return p\Php80::str_starts_with($haystack ?? '', $needle ?? ''); }
}
if (!function_exists('str_ends_with')) {
function str_ends_with(?string $haystack, ?string $needle): bool { return p\Php80::str_ends_with($haystack ?? '', $needle ?? ''); }
}
if (!function_exists('get_debug_type')) {
function get_debug_type($value): string { return p\Php80::get_debug_type($value); }
}
if (!function_exists('get_resource_id')) {
function get_resource_id($resource): int { return p\Php80::get_resource_id($resource); }
}`

@nicolas-grekas
Copy link
Member

there is a "post-autoload-dump" script that modify autoload but nothing linked with this error.

That might be the issue.
As you can see in the source, use Symfony\Polyfill\Php80 as p; means that p\Php80 really means Symfony\Polyfill\Php80\Php80.
The fact that the error tells about p\Php80 means that the use is not properly resolved.
The reason is on your side, not on this repo.
Closing therefore as we can't help past this point.
Good luck with debugging :)

@JL2014
Copy link
Author

JL2014 commented Dec 6, 2021

Hi @nicolas-grekas,

I removed our post-autoload-dump but the problem is still there.

The "vendor\composer\autoload_static.php" seems to be good (before encryption) :

...
'Symfony\\Polyfill\\Php72\\Php72' => __DIR__ . '/..' . '/symfony/polyfill/src/Php72/Php72.php',
'Symfony\\Polyfill\\Php73\\Php73' => __DIR__ . '/..' . '/symfony/polyfill/src/Php73/Php73.php',
'Symfony\\Polyfill\\Php74\\Php74' => __DIR__ . '/..' . '/symfony/polyfill/src/Php74/Php74.php',
'Symfony\\Polyfill\\Php80\\Php80' => __DIR__ . '/..' . '/symfony/polyfill/src/Php80/Php80.php',
'Symfony\\Polyfill\\Php81\\Php81' => __DIR__ . '/..' . '/symfony/polyfill/src/Php81/Php81.php',
'Symfony\\Polyfill\\Util\\Binary' => __DIR__ . '/..' . '/symfony/polyfill/src/Util/Binary.php',
...

I don't understand where is the resolution error.

Perhaps a link with the backslash used in class name ? (we can see double "\" in files on Windows)

Greetings.

@stof
Copy link
Member

stof commented Dec 6, 2021

The double \ is because \ is the escaping character in PHP strings, and so needs to be escaped. There is no issue about that.

I suspect that the issue might be related to your encryption layer then.

@JL2014
Copy link
Author

JL2014 commented Dec 6, 2021

Hi @stof,

I have open a ticket on the encryption software.

Thank you for your help everyone.

@admindotnu
Copy link

We experience same problems, did you found a solution for this ?

@JL2014
Copy link
Author

JL2014 commented Dec 13, 2021

Hi @admindotnu,

a ticket has been opened at our used encryption software, I will inform you if they find something.

for information, a possible workaround we use temporarily is to replace all occurrences of "p\Php80" by "Symfony\Polyfill\Php80\Php80".

Greetings.

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

No branches or pull requests

6 participants