mirror of
https://github.com/php/php-langspec.git
synced 2026-03-24 15:22: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
169 lines
3.5 KiB
PHP
169 lines
3.5 KiB
PHP
--TEST--
|
|
PHP Spec test generated from ./expressions/instanceof_operator/instanceof.php
|
|
--FILE--
|
|
<?php
|
|
|
|
/*
|
|
+-------------------------------------------------------------+
|
|
| Copyright (c) 2014 Facebook, Inc. (http://www.facebook.com) |
|
|
+-------------------------------------------------------------+
|
|
*/
|
|
|
|
error_reporting(-1);
|
|
|
|
///*
|
|
echo "------- Classes -------------\n";
|
|
|
|
// test using a series of classes, some derived
|
|
|
|
class C1 {}
|
|
class C2 {}
|
|
class D extends C1 {}
|
|
|
|
$c1 = new C1;
|
|
$c2 = new C2;
|
|
$c2b = new C2;
|
|
$d = new D;
|
|
|
|
var_dump($c1 instanceof C1);
|
|
var_dump($c1 instanceof C2);
|
|
var_dump($c1 instanceof D);
|
|
|
|
//var_dump($c1 instanceof "C1"); // can't be a string literal
|
|
//var_dump($c1 instanceof "c1"); // can't be a string literal
|
|
$clName = "C1";
|
|
var_dump($c1 instanceof $clName); // TRUE; can be a string
|
|
$clName = "C2";
|
|
var_dump($c1 instanceof $clName); // FALSE; can be a string
|
|
|
|
var_dump($c2 instanceof $c2b); //
|
|
var_dump($d instanceof $c1); //
|
|
var_dump($c1 instanceof $d); //
|
|
|
|
echo "--------------------\n";
|
|
|
|
function f1() { return new D; }
|
|
var_dump(f1() instanceof C1);
|
|
var_dump(f1() instanceof C2);
|
|
var_dump(f1() instanceof D);
|
|
|
|
echo "--------------------\n";
|
|
|
|
var_dump($c2 instanceof C1);
|
|
var_dump($c2 instanceof C2);
|
|
var_dump($c2 instanceof d);
|
|
|
|
echo "--------------------\n";
|
|
|
|
var_dump($d instanceof C1);
|
|
var_dump($d instanceof C2);
|
|
var_dump($d instanceof d);
|
|
|
|
echo "------- Interfaces -------------\n";
|
|
|
|
// test using a series of interfaces
|
|
|
|
interface I1 {}
|
|
interface I2 {}
|
|
class E1 implements I1, I2 {}
|
|
|
|
$e1 = new E1;
|
|
|
|
var_dump($e1 instanceof E1);
|
|
var_dump($e1 instanceof I1); // Yes
|
|
var_dump($e1 instanceof I2); // Yes
|
|
$iName = "I2";
|
|
var_dump($e1 instanceof $iName); // Yes
|
|
//var_dump($e1 instanceof "I2"); // No string literal allowed
|
|
|
|
echo "------- Non-Instances -------------\n";
|
|
|
|
// test using variables that are not instances
|
|
|
|
var_dump($d instanceof I1); // of course not!
|
|
$v = 10;
|
|
var_dump($v instanceof C1); // of course not!
|
|
$v = 1.234;
|
|
var_dump($v instanceof C1); // of course not!
|
|
$v = NULL;
|
|
var_dump($v instanceof C1); // of course not!
|
|
|
|
echo "------- Non-class/Non-interface types -------------\n";
|
|
|
|
// test against non-class/non-interface "types" and even non-types
|
|
|
|
$v = TRUE;
|
|
var_dump($v instanceof bool); // false!
|
|
var_dump($v instanceof int); // false!
|
|
var_dump($v instanceof float); // false!
|
|
var_dump($v instanceof string); // false!
|
|
//var_dump($v instanceof array); // won't parse
|
|
var_dump($v instanceof object); // false!
|
|
var_dump($v instanceof xyz); // false!
|
|
//*/
|
|
|
|
class C11 {} $c11 = new C11;
|
|
class C21 {} $c21 = new C21;
|
|
class D1 extends C11 {} $d = new D1;
|
|
var_dump($d instanceof C11);
|
|
var_dump($d instanceof C21);
|
|
var_dump($d instanceof D1);
|
|
|
|
// -----------------------------------------
|
|
|
|
interface I11 {}
|
|
interface I21 {}
|
|
|
|
class E11 implements I11, I21 {}
|
|
|
|
$e11 = new E11;
|
|
var_dump($e11 instanceof I11); // Yes
|
|
var_dump($e11 instanceof I21); // Yes
|
|
$iName = "I21";
|
|
var_dump($e11 instanceof $iName); // Yes
|
|
--EXPECT--
|
|
------- Classes -------------
|
|
bool(true)
|
|
bool(false)
|
|
bool(false)
|
|
bool(true)
|
|
bool(false)
|
|
bool(true)
|
|
bool(true)
|
|
bool(false)
|
|
--------------------
|
|
bool(true)
|
|
bool(false)
|
|
bool(true)
|
|
--------------------
|
|
bool(false)
|
|
bool(true)
|
|
bool(false)
|
|
--------------------
|
|
bool(true)
|
|
bool(false)
|
|
bool(true)
|
|
------- Interfaces -------------
|
|
bool(true)
|
|
bool(true)
|
|
bool(true)
|
|
bool(true)
|
|
------- Non-Instances -------------
|
|
bool(false)
|
|
bool(false)
|
|
bool(false)
|
|
bool(false)
|
|
------- Non-class/Non-interface types -------------
|
|
bool(false)
|
|
bool(false)
|
|
bool(false)
|
|
bool(false)
|
|
bool(false)
|
|
bool(false)
|
|
bool(true)
|
|
bool(false)
|
|
bool(true)
|
|
bool(true)
|
|
bool(true)
|
|
bool(true)
|