Files
archived-php-langspec/tests/classes/overloading.phpt
Nikita Popov 3261ea2f3b Merge branch 'PHP-5.6'
Conflicts:
	tests/arrays/arrays.php
	tests/arrays/arrays.php.expectf
	tests/basic_concepts/memory_model_and_array_types.php
	tests/basic_concepts/memory_model_and_array_types.php.expect
	tests/basic_concepts/memory_model_and_handle_types.php
	tests/basic_concepts/memory_model_and_resources.php.expect
	tests/basic_concepts/storage_duration.php
	tests/classes/__gets_return_type.php.expect
	tests/classes/__php_incomplete_class.php
	tests/classes/__php_incomplete_class.php.expect
	tests/classes/classes.php.expect
	tests/classes/cloning.php.expectf
	tests/classes/constructors.php.expect
	tests/classes/dynamic_methods.php.expectf
	tests/classes/dynamic_properties.php
	tests/classes/dynamic_properties.php.expect
	tests/classes/dynamic_properties2.php.expectf
	tests/classes/dynamic_properties3.php
	tests/classes/dynamic_properties3.php.expectf
	tests/classes/invoke.php.expect
	tests/classes/invoking.php.expect
	tests/classes/overloading.php
	tests/classes/overloading.php.expect
	tests/classes/overloading_2.php.expectf
	tests/classes/overloading_methods.php.expectf
	tests/classes/overloading_properties.php
	tests/classes/overloading_properties.php.expect
	tests/classes/overloading_properties2.php.expectf
	tests/classes/point2_test1.php.expect
	tests/classes/property_initializer.php
	tests/classes/property_initializer.php.expect
	tests/classes/serializable.php
	tests/classes/serializable.php.expect
	tests/classes/setting_state.php
	tests/classes/sleep_and_wakeup.php
	tests/classes/vehicle_test1.php.expect
	tests/constants/classes.php
	tests/constants/classes.php.expect
	tests/constants/constants.php
	tests/constants/constants.php.expectf
	tests/exception_handling/exception_class_experiment_1.php
	tests/exception_handling/hierarchy_of_exception_classes.php.expect
	tests/exception_handling/jump_from_catch_or_finally_clause.php
	tests/exception_handling/jump_from_catch_or_finally_clause.php.expect
	tests/exception_handling/odds_and_ends.php.expect
	tests/expressions/additive_operators/addition_subtraction_concatenation.php.expect
	tests/expressions/additive_operators/array_concatenation.php
	tests/expressions/additive_operators/array_concatenation.php.expectf
	tests/expressions/assignment_operators/assignment.php.expect
	tests/expressions/binary_logical_operators/binary_logical_operators.php.expect
	tests/expressions/bitwise_and,_or,_xor_operators/bitwise_and_or_xor.php.expect
	tests/expressions/bitwise_shift_operators/bitwise_shift.php
	tests/expressions/bitwise_shift_operators/bitwise_shift.php.expect
	tests/expressions/equality_operators/comparisons.php.expectf
	tests/expressions/error_control_operator/error_control.php.expectf
	tests/expressions/general/associativity.php.expect
	tests/expressions/general/order_of_evaluation.php.expect
	tests/expressions/general/precedence.php.expect
	tests/expressions/general/sequence_points.php.expect
	tests/expressions/instanceof_operator/instanceof.php
	tests/expressions/instanceof_operator/instanceof.php.expect
	tests/expressions/multiplicative_operators/multiplication_division_modulus.php.expectf
	tests/expressions/postfix_operators/exponentiation.php.expect
	tests/expressions/postfix_operators/member_selection_operator.php
	tests/expressions/postfix_operators/post-increment_and_decrement_integer_edge_cases.php.expect
	tests/expressions/postfix_operators/scope_resolution_operator.php.expect
	tests/expressions/postfix_operators/subscripting.php
	tests/expressions/primary_expressions/intrinsics_echo.php.expect
	tests/expressions/primary_expressions/intrinsics_eval.php.expect
	tests/expressions/primary_expressions/intrinsics_exit.php.expect
	tests/expressions/primary_expressions/intrinsics_print.php.expect
	tests/expressions/primary_expressions/primary.php.expect
	tests/expressions/relational_operators/comparisons1.php.expectf
	tests/expressions/relational_operators/comparisons2.php.expectf
	tests/expressions/relational_operators/comparisons3.php.expectf
	tests/expressions/relational_operators/comparisons4.php.expectf
	tests/expressions/relational_operators/comparisons5.php.expectf
	tests/expressions/source_file_inclusion/include.php
	tests/expressions/source_file_inclusion/require.php
	tests/expressions/unary_operators/cast.php
	tests/expressions/unary_operators/cast.php.expectf
	tests/expressions/unary_operators/pre-increment_and_decrement_integer_edge_cases.php.expect
	tests/expressions/unary_operators/unary_arithmetic_operators.php.expect
	tests/functions/anonymous_functions.php
	tests/functions/basics.php
	tests/functions/byrefs.php.expectf
	tests/functions/byrefs_in_array_elements.php.expect
	tests/functions/conditionally_defined_function.php
	tests/functions/conditionally_defined_function.php.expect
	tests/functions/order_of_evaluation.php
	tests/functions/order_of_evaluation.php.expectf
	tests/functions/passing_arguments.php
	tests/functions/recursion.php.expect
	tests/functions/type_hints.php.expect
	tests/functions/variable_functions.php.expect
	tests/interfaces/interfaces.php.expect
	tests/interfaces/vector.php.expect
	tests/lexical_structure/comments.php.expect
	tests/lexical_structure/keywords.php.expect
	tests/lexical_structure/tokens/array_literals.php
	tests/lexical_structure/tokens/array_literals.php.expect
	tests/lexical_structure/tokens/integer_literals_edge_cases.php.expect
	tests/lexical_structure/tokens/point.php
	tests/lexical_structure/tokens/point2.php
	tests/namespaces/name_lookup.php.expect
	tests/namespaces/namespaces1.php
	tests/namespaces/namespaces1.php.expect
	tests/namespaces/namespaces2.php.expect
	tests/namespaces/using_namespaces_2.php
	tests/namespaces/using_namespaces_3.php.expect
	tests/phpt/expressions/source_file_inclusion/limits.inc
	tests/phpt/expressions/source_file_inclusion/mycolors.inc
	tests/scope/scope.php.expect
	tests/statements/expression_statement.php.expect
	tests/statements/iteration/do.php.expect
	tests/statements/iteration/for.php.expect
	tests/statements/jump/break.php.expect
	tests/statements/jump/continue.php.expect
	tests/statements/jump/goto.php.expect
	tests/statements/selection/if.php.expectf
	tests/statements/selection/switch.php
	tests/statements/selection/switch.php.expect
	tests/traits/traits.php
	tests/types/resource/resources.php.expect
	tests/variables/unsetting_variables.php.expectf
	tests/variables/variable_kinds.php
	tests/variables/variable_kinds.php.expect
	tests/variables/variable_variables.php
	tests/variables/variable_variables.php.expectf
2015-01-07 22:49:46 +01:00

219 lines
5.1 KiB
PHP

--TEST--
PHP Spec test generated from ./classes/overloading.php
--FILE--
<?php
error_reporting(-1);
class Point
{
private $x;
private $y;
private $dynamicProperties = array();
public $dummy = -100; // for test purposes only
public function __construct($x = 0, $y = 0)
{
$this->x = $x;
$this->y = $y;
}
public function __set($name, $value)
{
// echo __METHOD__ . "($name, $value)\n";
echo __METHOD__ . "($name, xx)\n"; // used if $value can't be converted to string
$this->dynamicProperties[$name] = $value;
}
public function __get($name)
{
echo __METHOD__ . "($name)\n";
if (array_key_exists($name, $this->dynamicProperties))
{
return $this->dynamicProperties[$name];
}
// no-such-property error handling goes here
return null;
}
public function __isset($name)
{
echo __METHOD__ . "($name)\n";
return isset($this->dynamicProperties[$name]);
}
public function __unset($name)
{
echo __METHOD__ . "($name)\n";
unset($this->dynamicProperties[$name]);
}
}
$p = new Point(5, 9);
echo "----------------------\n";
$v = $p->dummy; // get visible property
echo "dummy: $v\n";
$v = $p->__get('dummy'); // get dynamic property, if one exists; else, fails
echo "dynamic dummy: $v\n";
$p->dummy = 987; // set visible property
$p->__set('dummy', 456); // set dynamic property
$v = $p->dummy; // get visible property
echo "dummy: $v\n";
$v = $p->__get('dummy'); // get dynamic property
echo "dynamic dummy: $v\n";
echo "----------------------\n";
var_dump(isset($p->dummy)); // test if dummy exists and is accessible, or is dynamic
var_dump($p->__isset('dummy')); // test if dynamic dummy exists
echo "----------------------\n";
$v = $p->x; // try to get at an invisible property; can't. The runtime sees that x
// exists, but is invisible, so it calls __get to search for a dynamic
// property of that name, which fails. NULL is returned.
var_dump($v);
echo "----------------------\n";
var_dump(isset($p->x)); // test if x exists and is accessible, or is dynamic
var_dump($p->__isset('x')); // test if x exists and is accessible, or is dynamic
$p->x = 200;
var_dump($p->x);
var_dump(isset($p->x)); // test if x exists and is accessible, or is dynamic
var_dump($p->__isset('x')); // test if x exists and is accessible, or is dynamic
echo "----------------------\n";
$p->color = "red"; // set dynamic property
$v = $p->color; // get dynamic property
echo "color: $v\n";
echo "----------------------\n";
var_dump(isset($p->color)); // test if color exists and is accessible, or is dynamic
echo "----------------------\n";
$v = $p->dummy = 555;
echo "\$v: $v, dummy: " . $p->dummy . "\n";
$v = $p->color = "White"; // this calls __set but not __get
echo "\$v: $v, color: " . $p->color . "\n";
echo "----------------------\n";
var_dump(isset($p->dummy));
var_dump($p->__isset('dummy')); // test if x exists and is accessible, or is dynamic
$p->__unset('dummy');
var_dump(isset($p->dummy));
var_dump($p->__isset('dummy')); // test if x exists and is accessible, or is dynamic
unset($p->abc); // request to unset a non-existent is ignored
unset($p->x); // request to unset an inaccessible is ignored
var_dump(isset($p->dummy));
unset($p->dummy); // request to unset a declared accessible is OK
var_dump(isset($p->dummy));
var_dump(isset($p->color));
unset($p->color); //
var_dump(isset($p->color));
echo "----------------------\n";
class X
{
public function __destruct()
{
echo __METHOD__ . "\n";
}
}
///*
$p->thing = new X; // set dynamic property to an instance having a destructor
$v = $p->thing;
var_dump($v);
//unset($p->thing); // was sort-of expecting this to trigger the destructor, but ...
//$p->__unset('thing');
//echo "unset(\$p->thing) called\n";
//*/
// at program termination, the destructor for the dynamic property is called
--EXPECT--
----------------------
dummy: -100
Point::__get(dummy)
dynamic dummy:
Point::__set(dummy, xx)
dummy: 987
Point::__get(dummy)
dynamic dummy: 456
----------------------
bool(true)
Point::__isset(dummy)
bool(true)
----------------------
Point::__get(x)
NULL
----------------------
Point::__isset(x)
bool(false)
Point::__isset(x)
bool(false)
Point::__set(x, xx)
Point::__get(x)
int(200)
Point::__isset(x)
bool(true)
Point::__isset(x)
bool(true)
----------------------
Point::__set(color, xx)
Point::__get(color)
color: red
----------------------
Point::__isset(color)
bool(true)
----------------------
$v: 555, dummy: 555
Point::__set(color, xx)
Point::__get(color)
$v: White, color: White
----------------------
bool(true)
Point::__isset(dummy)
bool(true)
Point::__unset(dummy)
bool(true)
Point::__isset(dummy)
bool(false)
Point::__unset(abc)
Point::__unset(x)
bool(true)
Point::__isset(dummy)
bool(false)
Point::__isset(color)
bool(true)
Point::__unset(color)
Point::__isset(color)
bool(false)
----------------------
Point::__set(thing, xx)
Point::__get(thing)
object(X)#2 (0) {
}
X::__destruct