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

Cannot access property started with '\0' #71

Closed
mircobabini opened this issue Jan 8, 2021 · 3 comments · May be fixed by #90
Closed

Cannot access property started with '\0' #71

mircobabini opened this issue Jan 8, 2021 · 3 comments · May be fixed by #90

Comments

@mircobabini
Copy link

PHP Fatal error: Uncaught Error: Cannot access property started with '\0' in /wp-content/plugins/better-search-replace/includes/class-bsr-db.php:344

It's a known issue on PHP 7.3.
This is because of the empty char which IS NOT exactly an empty character but "*_".
You can't have a property starting with *.

$item->*_tbl becomes $item->\0_tbl. It's from the wp_options in my case.

Btw, solution is:

$key = trim( $key );
$this->$key = ...
sumonst21 added a commit to sumonst21/better-search-replace that referenced this issue Jun 28, 2022
Resolves deliciousbrains#71 PHP Fatal error:  Uncaught Error: Cannot access property started with '\0' in /var/www/quick2web/wp-content/plugins/better-search-replace/includes/class-bsr-db.php:344
@mapsmarketing
Copy link

Thank you very much @mircobabini

@jdreesen
Copy link

jdreesen commented Jan 2, 2023

Sounds more like you're dealing with the array representation of a protected property, whose key would be of format \0*\0property_name. Just trimming the \0 wouldn't help here, because:

You can't have a property starting with *

Yes, you can if you set it like this: https://3v4l.org/P81e4, which is exactly what your proposed fix is doing.
What you can't have is a property starting with \0, though, which is why your fix seems to work.
But this wouldn't help, because it's a different name that's nobody going to use (also: this is deprecated in PHP 8.2).

My proposal would be to skip those properties via:

if (!str_starts_with($key , "\0")) {
    $_tmp->$key = ...
}

@AhmedTheGeek
Copy link
Contributor

Thanks for the report @mircobabini, and the fix suggestion @jdreesen. This issue has been resolved by #101.

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

Successfully merging a pull request may close this issue.

4 participants