• Resolved cimatti

    (@cimatti)


    Hello,

    I’m moving my sites to a server with PHP 7.1, so I’m checking the code for compatibility using PHPCompatibility and PHPCodeSniffer

    I found the following errors in wp-content/plugins/types/library/toolset/types/embedded/includes/fields/entry.php

     191 | ERROR | Indirect access to variables, properties and methods will be evaluated strictly in left-to-right order since PHP 7.0. Use curly braces to remove ambiguity.
     192 | ERROR | Indirect access to variables, properties and methods will be evaluated strictly in left-to-right order since PHP 7.0. Use curly braces to remove ambiguity.

    The context is:

        if( isset( $field['post_type'] ) ) {
            $post_type = get_post_type_object($post_type);
            if (
                !isset($post_type->$field['post_type'])
                || empty($post_type->$field['post_type'])
            ) {
                return false;
            }
        }

    The problem is with the two occurrences of $post_type->$field['post_type'] as for PHP 5.* that expression is equivalent to $post_type->{$field['post_type']} but in PHP 7.* it is interpreted as ($post_type->$field)['post_type']

    It seems the PHP 5 interpretation is the right one, so i replaced the code with $post_type->{$field['post_type']} , is it correct?

    Can you include this fix in the next release?
    Thanks

    [edit: I pasted the wrong file path, now it’s correct]

    • This topic was modified 8 years, 12 months ago by cimatti.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Anonymous User 14808221

    (@anonymized-14808221)

    Our plugin is fully compatible with php 7+.

    You don’t need to make any adjustments.

    It’s elaborated here:
    https://wp-types.com/toolset-requirements/

    Thread Starter cimatti

    (@cimatti)

    I’m sorry to disagree, but as I explained above, that part of code is interpreted in two different ways in PHP 5.* and 7.*

    See http://php.net/manual/en/migration70.incompatible.php#migration70.incompatible.variable-handling.indirect for reference

    You may have not noticed this because this incompatibility doesn’t generates PHP errors, because the expression is inside isset() and empty(), that are two language constructs that tests the expression without issuing errors in any case

    I’m not sure how much important is this part of code and what implications would have in the normal execution of your plugin, but in PHP 7.* this unfixed code will return always false even if $post_type->{$field['post_type']} contains something

    Anonymous User 14808221

    (@anonymized-14808221)

    Our Developers produce the plugin to be compatible with PHP 5.3 and above

    I am quite sure the code above has a pendant to be compatible with all the versions.
    To be sure and not tell things just based on our own DOC, I will request the feedback of a Developer and update you accordingly

    Thank you for your patience meanwhile.

    Anonymous User 14808221

    (@anonymized-14808221)

    Ok, this was my bad.

    But, the code was never used. It was part of the plan to have an “Entry” field.
    The “unfinished” code got released, and that is bad.

    We will delete it for the upcoming release.

    Thank you a lot for reporting it.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Incompatibility with PHP 7.* and fix’ is closed to new replies.