• Resolved bartkleinreesink

    (@bartkleinreesink)


    With PHP 8.1 officially released, I think it’s only fair to support this version.

    Please fix the following error:

    trim(): Passing null to parameter #1 ($string) of type string is deprecated

    Located in:

    better-wp-security/core/core.php:1102

    Could be fixed as easily as:

                if (null !== $home_path) {
                    $home_path = trim($home_path, '/');
                }
Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @bartkleinreesink,

    1. If I’m not mistaken it’s not an error, but a PHP deprecation notice. But it definately needs to be taken care of. That’s exactly what these PHP 8.1 deprecation notices are for ??

    2. According to the iTSec plugin 8.1.3 Changelog:

    Bug Fix: Preliminary PHP 8.1 compatibility.

    So it looks like PHP 8.1 compatibility is a work in progress.

    3. I prefer a type casting solution:

    1101 $home_path = (string) parse_url( get_option( 'home' ), PHP_URL_PATH );
    1102 $home_path = trim( $home_path, '/' );

    4. It may be worth looking into why parse_url( get_option( 'home' ), PHP_URL_PATH ) returns a null value. There is a lot (filters) happening in the WordPress core get_option() function. And according to the PHP doc of the parse_url() function:

    If the requested component doesn’t exist within the given URL, null will be returned.

    I may be wrong but parse_url( get_option( 'home' ), PHP_URL_PATH ) should “normally” return the (string) path value from the Site Address (URL) field in the WordPress General Settings page. That said there may be a very good reason why it returns a null value in your env.

    +++++ To prevent any confusion, I’m not iThemes +++++

    • This reply was modified 1 year, 11 months ago by nlpro.
    • This reply was modified 1 year, 11 months ago by nlpro.
    Thread Starter bartkleinreesink

    (@bartkleinreesink)

    Thanks for your reply. To be very honest, I wrote my message in a hurry and didn’t take a good look at it. It indeed is strange get_option('home') returns null.

    I’m going to have to check why that even happens in the first place.

    Anyhow, thanks for taking a look.

    Edit: Had a look, the typecasting option is indeed the best idea. It does need fixing, though. The reason why parse_url(get_option('home'), PHP_URL_PATH); returns null is because my home url doesn’t anything after the base url. So it’s only logical it returns nothing.

    Hmm, sometimes an explanation is staring you in the face but you just don’t see it.

    Anyway, when the Site Address (URL) field value equals a scheme and domain (but no path) like https://www.example.com then running the iTSec plugin on PHP 8.1 will generate the PHP 8.1 deprecation notice as reported in this topic.

    It’s the PHP parse_url() function that will return the null value (as mentioned in my previous post). No need to dig into the WordPress core get_option() code.

    I thought your site was running into an edge case, but it’s actually happening in a standard/common WordPress install.

    If WordPress is installed in a subdirectory (which is how I often run WordPress), then this is not an issue.

    Anyway, makes no difference for the solution ??
    Definately needs to be fixed.

    Post Edit: Ah, just read your last post. You figured it out already. Good work!

    • This reply was modified 1 year, 11 months ago by nlpro.

    Yup, PHP 8.1 is something that is still being worked on, as @nlpro mentioned. Technically PHP 8.1 is still in beta support for WordPress, so it’s not recommended for production sites.

    Edit: I forgot to link this https://make.www.ads-software.com/hosting/handbook/server-environment/#php

    • This reply was modified 1 year, 11 months ago by Matthew.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘PHP 8.1 compatibility’ is closed to new replies.