<?php
class With_Magic_Methods {
private $_args;
protected $compat_fields = array( '_args' );
public function __get( $name ) {
if ( in_array( $name, $this->compat_fields, true ) ) {
return $this->$name;
}
}
public function __set( $name, $value ) {
if ( in_array( $name, $this->compat_fields, true ) ) {
return $this->$name = $value;
}
}
public function __isset( $name ) {
if ( in_array( $name, $this->compat_fields, true ) ) {
return isset( $this->$name );
}
return false;
}
public function __unset( $name ) {
if ( in_array( $name, $this->compat_fields, true ) ) {
unset( $this->$name );
}
}
}
class No_Magic_Methods {
public $_args;
}
class WP_31_Version {
/**
* Various information about the current table
*
* @since 3.1.0
* @var array
* @access private
*/
var $_args;
/**
* Constructor. The child class should call this constructor from it's own constructor
*
* @param array $args An associative array with information about the current table
* @access protected
*/
function WP_List_Table( $args = array() ) {}
}
$wp_31_version = new WP_31_Version();
$current = new With_Magic_Methods();
$option2 = new No_Magic_Methods();
function _get() {
global $wp_31_version, $current, $option2;
echo "- - - - - - - - - - -\n";
echo "š Defined property: \n";
echo "- - - - - - - - - - -\n";
echo "šø WP 3.1 code: ";
var_dump( $wp_31_version->_args );
echo "\nšø Current code: ";
var_dump( $current->_args );
echo "\nšø Option 2: ";
var_dump( $option2->_args );
echo "\n- - - - - - - - - - -\n";
echo "š Dynamic property: \n";
echo "- - - - - - - - - - -\n";
echo "šø WP 3.1 code: ";
var_dump( $wp_31_version->_dynamic_property );
echo "\nšø Current code: ";
var_dump( $current->_dynamic_property );
echo "\nšø Option 2: ";
var_dump( $option2->_dynamic_property );
}
function test_get( $message = '' ) {
echo "*********************\n";
printf( "š¶š¶ Test get%s š¶š¶\n", $message );
echo "*********************\n\n";
_get();
echo "\n\n";
}
function test_isset( $message = '' ) {
global $wp_31_version, $current, $option2;
echo "*********************\n";
printf( "š¶š¶ Test isset()%s š¶š¶\n", $message );
echo "*********************\n\n";
echo "- - - - - - - - - - -\n";
echo "š Defined property: \n";
echo "- - - - - - - - - - -\n";
echo "šø WP 3.1 code: ";
var_dump( isset( $wp_31_version->_args ) );
echo "\nšø Current code: ";
var_dump( isset( $current->_args ) );
echo "\nšø Option 2: ";
var_dump( isset( $option2->_args ) );
echo "\n- - - - - - - - - - -\n";
echo "š Dynamic property: \n";
echo "- - - - - - - - - - -\n";
echo "šø WP 3.1 code: ";
var_dump( isset( $wp_31_version->_dynamic_property ) );
echo "\nšø Current code: ";
var_dump( isset( $current->_dynamic_property ) );
echo "\nšø Option 2: ";
var_dump( isset( $option2->_dynamic_property ) );
echo "\n\n";
}
function test_set( $message = '' ) {
global $wp_31_version, $current, $option2;
$new_value = array( 'test' );
$wp_31_version->_args = $new_value;
$wp_31_version->_dynamic_property = $new_value;
$current->_args = $new_value;
$current->_dynamic_property = $new_value;
$option2->_args = $new_value;
$option2->_dynamic_property = $new_value;
echo "*********************\n";
printf( "š¶š¶ Test set%s š¶š¶\n\n", $message );
echo "*********************\n";
_get();
echo "\n\n";
}
echo "\n ***** COMPARE WITH WP 3.1 WP_List_Table ***** \n\n";
test_get();
test_isset();
test_set();
// Unset.
unset( $wp_31_version->_args );
unset( $wp_31_version->_dynamic_property );
unset( $current->_args );
unset( $current->_dynamic_property );
unset( $option2->_args );
unset( $option2->_dynamic_property );
test_get( ' after unset()' );
test_isset( ' after unset()' );
test_set( ' after unset()' );
test_isset( ' after unset() and set' );
run_test();
preferences:
23.39 ms | 406 KiB | 5 Q