mirror of
https://github.com/php/php-langspec.git
synced 2026-03-24 07:12:08 +01:00
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
278 lines
4.9 KiB
PHP
278 lines
4.9 KiB
PHP
--TEST--
|
|
PHP Spec test generated from ./classes/setting_state.php
|
|
--FILE--
|
|
<?php
|
|
|
|
/*
|
|
+-------------------------------------------------------------+
|
|
| Copyright (c) 2014 Facebook, Inc. (http://www.facebook.com) |
|
|
+-------------------------------------------------------------+
|
|
*/
|
|
|
|
error_reporting(-1);
|
|
|
|
class Point
|
|
{
|
|
private static $pointCount = 0;
|
|
|
|
private $x;
|
|
private $y;
|
|
const CON = 10;
|
|
protected static $prots;
|
|
protected $proti;
|
|
public $pubi;
|
|
|
|
public static function getPointCount()
|
|
{
|
|
return self::$pointCount;
|
|
}
|
|
|
|
public function __construct($x = 0, $y = 0)
|
|
{
|
|
$this->x = $x;
|
|
$this->y = $y;
|
|
++self::$pointCount;
|
|
|
|
echo "\nInside " . __METHOD__ . ", $this, point count = " . self::$pointCount . "\n\n";
|
|
}
|
|
|
|
public function move($x, $y)
|
|
{
|
|
$this->x = $x;
|
|
$this->y = $y;
|
|
}
|
|
|
|
public function translate($x, $y)
|
|
{
|
|
$this->x += $x;
|
|
$this->y += $y;
|
|
}
|
|
|
|
public function __destruct()
|
|
{
|
|
--self::$pointCount;
|
|
|
|
echo "\nInside " . __METHOD__ . ", $this, point count = " . self::$pointCount . "\n\n";
|
|
}
|
|
///*
|
|
public function __clone()
|
|
{
|
|
++self::$pointCount;
|
|
|
|
echo "\nInside " . __METHOD__ . ", $this, point count = " . self::$pointCount . "\n\n";
|
|
}
|
|
//*/
|
|
|
|
public function __toString()
|
|
{
|
|
return '(' . $this->x . ',' . $this->y . ')';
|
|
}
|
|
///*
|
|
static public function __set_state(array $properties)
|
|
{
|
|
echo "Inside " . __METHOD__ . "\n";
|
|
var_dump($properties);
|
|
|
|
$p = new Point;
|
|
$p->x = $properties['x'];
|
|
$p->y = $properties['y'];
|
|
var_dump($p);
|
|
return $p;
|
|
}
|
|
//*/
|
|
}
|
|
|
|
echo "---------------- start -------------------\n";
|
|
|
|
$p = new Point(3, 5);
|
|
|
|
echo "---------------- calling var_export -------------------\n";
|
|
|
|
$v = var_export($p, TRUE);
|
|
var_dump($v);
|
|
|
|
echo "---------------- calling eval -------------------\n";
|
|
|
|
eval('$z = ' . $v . ";");
|
|
echo "Point \$z is $z\n";
|
|
|
|
unset($p, $v, $z);
|
|
|
|
echo "---------------- test with inheritance -------------------\n";
|
|
|
|
class B
|
|
{
|
|
private $bprop;
|
|
|
|
public function __construct($p)
|
|
{
|
|
$this->bprop = $p;
|
|
}
|
|
|
|
static public function __set_state(array $properties)
|
|
{
|
|
echo "Inside " . __METHOD__ . "\n";
|
|
var_dump($properties);
|
|
|
|
$b = new static($properties['bprop']);
|
|
// $b->bprop = $properties['bprop'];
|
|
var_dump($b);
|
|
echo "about to return from " . __METHOD__ . "\n";
|
|
return $b;
|
|
}
|
|
}
|
|
|
|
class D extends B
|
|
{
|
|
private $dprop = 123;
|
|
|
|
public function __construct($bp, $dp = NULL)
|
|
{
|
|
$this->dprop = $dp;
|
|
parent::__construct($bp);
|
|
}
|
|
///*
|
|
static public function __set_state(array $properties)
|
|
{
|
|
echo "Inside " . __METHOD__ . "\n";
|
|
var_dump($properties);
|
|
|
|
$d = parent::__set_state($properties);
|
|
var_dump($d);
|
|
$d->dprop = $properties['dprop'];
|
|
var_dump($d);
|
|
echo "about to return from " . __METHOD__ . "\n";
|
|
return $d;
|
|
}
|
|
//*/
|
|
}
|
|
|
|
echo "---------------- test with type B -------------------\n";
|
|
|
|
$b = new B(10);
|
|
$v = var_export($b, TRUE);
|
|
var_dump($v);
|
|
|
|
$r = eval('$z = ' . $v . ";");
|
|
var_dump($z);
|
|
|
|
echo "---------------- test with type D -------------------\n";
|
|
|
|
$d = new D(20, 30);
|
|
$v = var_export($d, TRUE);
|
|
var_dump($v);
|
|
|
|
$r = eval('$z = ' . $v . ";");
|
|
var_dump($z);
|
|
|
|
echo "---------------- end -------------------\n";
|
|
--EXPECTF--
|
|
---------------- start -------------------
|
|
|
|
Inside Point::__construct, (3,5), point count = 1
|
|
|
|
---------------- calling var_export -------------------
|
|
string(%d) "Point::__set_state(array(
|
|
%w 'x' => 3,
|
|
%w 'y' => 5,
|
|
%w 'proti' => NULL,
|
|
%w 'pubi' => NULL,
|
|
))"
|
|
---------------- calling eval -------------------
|
|
Inside Point::__set_state
|
|
array(4) {
|
|
["x"]=>
|
|
int(3)
|
|
["y"]=>
|
|
int(5)
|
|
["proti"]=>
|
|
NULL
|
|
["pubi"]=>
|
|
NULL
|
|
}
|
|
|
|
Inside Point::__construct, (0,0), point count = 2
|
|
|
|
object(Point)#2 (4) {
|
|
["x":"Point":private]=>
|
|
int(3)
|
|
["y":"Point":private]=>
|
|
int(5)
|
|
["proti":protected]=>
|
|
NULL
|
|
["pubi"]=>
|
|
NULL
|
|
}
|
|
Point $z is (3,5)
|
|
|
|
Inside Point::__destruct, (3,5), point count = 1
|
|
|
|
|
|
Inside Point::__destruct, (3,5), point count = 0
|
|
|
|
---------------- test with inheritance -------------------
|
|
---------------- test with type B -------------------
|
|
string(%d) "B::__set_state(array(
|
|
%w 'bprop' => 10,
|
|
))"
|
|
Inside B::__set_state
|
|
array(1) {
|
|
["bprop"]=>
|
|
int(10)
|
|
}
|
|
object(B)#%d (1) {
|
|
["bprop":"B":private]=>
|
|
int(10)
|
|
}
|
|
about to return from B::__set_state
|
|
object(B)#%d (1) {
|
|
["bprop":"B":private]=>
|
|
int(10)
|
|
}
|
|
---------------- test with type D -------------------
|
|
string(%d) "D::__set_state(array(
|
|
%w 'dprop' => 30,
|
|
%w 'bprop' => 20,
|
|
))"
|
|
Inside D::__set_state
|
|
array(2) {
|
|
["dprop"]=>
|
|
int(30)
|
|
["bprop"]=>
|
|
int(20)
|
|
}
|
|
Inside B::__set_state
|
|
array(2) {
|
|
["dprop"]=>
|
|
int(30)
|
|
["bprop"]=>
|
|
int(20)
|
|
}
|
|
object(D)#%d (2) {
|
|
["dprop":"D":private]=>
|
|
NULL
|
|
["bprop":"B":private]=>
|
|
int(20)
|
|
}
|
|
about to return from B::__set_state
|
|
object(D)#%d (2) {
|
|
["dprop":"D":private]=>
|
|
NULL
|
|
["bprop":"B":private]=>
|
|
int(20)
|
|
}
|
|
object(D)#%d (2) {
|
|
["dprop":"D":private]=>
|
|
int(30)
|
|
["bprop":"B":private]=>
|
|
int(20)
|
|
}
|
|
about to return from D::__set_state
|
|
object(D)#%d (2) {
|
|
["dprop":"D":private]=>
|
|
int(30)
|
|
["bprop":"B":private]=>
|
|
int(20)
|
|
}
|
|
---------------- end -------------------
|