Make WordPress Core

Changeset 56356


Ignore:
Timestamp:
08/03/2023 07:50:20 PM (17 months ago)
Author:
hellofromTonya
Message:

Code Modernization: Use "declare" in WP_List_Table magic methods deprecation message

Changes "define" to "declare" in the deprecation message in WP_List_Table magic methods.

Why is "declare" better?
It aligns well to:

  • the topic of and published information about dynamic properties.
  • the act of explicitly listing the variable as a property on the class.

The goal of this message is guide developers to change their code. Changing the term to "declare" hopefully will aid in the understanding of what is being asked of developers when this deprecation is thrown.

Follow-up [56349].

Props hellofromTonya, antonvlasenko.
Fixes #58896.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-list-table.php

    r56349 r56356  
    188188
    189189        trigger_error(
    190             "The property `{$name}` is not defined. Getting a dynamic (undefined) property is " .
    191             'deprecated since version 6.4.0! Instead, define the property on the class.',
     190            "The property `{$name}` is not declared. Getting a dynamic property is " .
     191            'deprecated since version 6.4.0! Instead, declare the property on the class.',
    192192            E_USER_DEPRECATED
    193193        );
     
    211211
    212212        trigger_error(
    213             "The property `{$name}` is not defined. Setting a dynamic (undefined) property is " .
    214             'deprecated since version 6.4.0! Instead, define the property on the class.',
     213            "The property `{$name}` is not declared. Setting a dynamic property is " .
     214            'deprecated since version 6.4.0! Instead, declare the property on the class.',
    215215            E_USER_DEPRECATED
    216216        );
     
    232232
    233233        trigger_error(
    234             "The property `{$name}` is not defined. Checking `isset()` on a dynamic (undefined) property " .
    235             'is deprecated since version 6.4.0! Instead, define the property on the class.',
     234            "The property `{$name}` is not declared. Checking `isset()` on a dynamic property " .
     235            'is deprecated since version 6.4.0! Instead, declare the property on the class.',
    236236            E_USER_DEPRECATED
    237237        );
     
    254254
    255255        trigger_error(
    256             "A property `{$name}` is not defined. Unsetting a dynamic (undefined) property is " .
    257             'deprecated since version 6.4.0! Instead, define the property on the class.',
     256            "A property `{$name}` is not declared. Unsetting a dynamic property is " .
     257            'deprecated since version 6.4.0! Instead, declare the property on the class.',
    258258            E_USER_DEPRECATED
    259259        );
  • trunk/tests/phpunit/tests/admin/wpListTable.php

    r56349 r56356  
    372372     * @param mixed $expected       Expected value.
    373373     */
    374     public function test_should_get_compat_fields_defined_property( $property_name, $expected ) {
     374    public function test_should_get_compat_fields( $property_name, $expected ) {
    375375        $list_table = new WP_List_Table( array( 'plural' => '_wp_tests__get' ) );
    376376
     
    390390        $this->expectDeprecation();
    391391        $this->expectDeprecationMessage(
    392             'The property `undefined_property` is not defined. Getting a dynamic (undefined) property is ' .
    393             'deprecated since version 6.4.0! Instead, define the property on the class.'
    394         );
    395         $this->assertNull( $this->list_table->undefined_property, 'Getting a dynamic property should return null from WP_List_Table::__get()' );
     392            'The property `undeclared_property` is not declared. Getting a dynamic property is ' .
     393            'deprecated since version 6.4.0! Instead, declare the property on the class.'
     394        );
     395        $this->assertNull( $this->list_table->undeclared_property, 'Getting a dynamic property should return null from WP_List_Table::__get()' );
    396396    }
    397397
     
    419419        $this->expectDeprecation();
    420420        $this->expectDeprecationMessage(
    421             'The property `undefined_property` is not defined. Setting a dynamic (undefined) property is ' .
    422             'deprecated since version 6.4.0! Instead, define the property on the class.'
    423         );
    424         $this->list_table->undefined_property = 'some value';
     421            'The property `undeclared_property` is not declared. Setting a dynamic property is ' .
     422            'deprecated since version 6.4.0! Instead, declare the property on the class.'
     423        );
     424        $this->list_table->undeclared_property = 'some value';
    425425    }
    426426
     
    434434     * @param mixed $expected       Expected value.
    435435     */
    436     public function test_should_isset_compat_fields_defined_property( $property_name, $expected ) {
     436    public function test_should_isset_compat_fields( $property_name, $expected ) {
    437437        $actual = isset( $this->list_table->$property_name );
    438438        if ( is_null( $expected ) ) {
     
    451451        $this->expectDeprecation();
    452452        $this->expectDeprecationMessage(
    453             'The property `undefined_property` is not defined. Checking `isset()` on a dynamic (undefined) property ' .
    454             'is deprecated since version 6.4.0! Instead, define the property on the class.'
    455         );
    456         $this->assertFalse( isset( $this->list_table->undefined_property ), 'Checking a dyanmic property should return false from WP_List_Table::__isset()' );
     453            'The property `undeclared_property` is not declared. Checking `isset()` on a dynamic property ' .
     454            'is deprecated since version 6.4.0! Instead, declare the property on the class.'
     455        );
     456        $this->assertFalse( isset( $this->list_table->undeclared_property ), 'Checking a dynamic property should return false from WP_List_Table::__isset()' );
    457457    }
    458458
     
    478478        $this->expectDeprecation();
    479479        $this->expectDeprecationMessage(
    480             'A property `undefined_property` is not defined. Unsetting a dynamic (undefined) property is ' .
    481             'deprecated since version 6.4.0! Instead, define the property on the class.'
    482         );
    483         unset( $this->list_table->undefined_property );
     480            'A property `undeclared_property` is not declared. Unsetting a dynamic property is ' .
     481            'deprecated since version 6.4.0! Instead, declare the property on the class.'
     482        );
     483        unset( $this->list_table->undeclared_property );
    484484    }
    485485
Note: See TracChangeset for help on using the changeset viewer.