Skip to content

Add support for the mixed type #5313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Zend/tests/type_declarations/mixed/casting/mixed_cast_error.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--TEST--
Test that a mixed casting is not supported
--FILE--
<?php

$foo = (mixed) 12;

?>
--EXPECTF--
Parse error: syntax error, unexpected '12' (T_LNUMBER) in %s on line %d
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Test that a mixed parameter type can't be overridden by a built-in type
--FILE--
<?php

class Foo
{
public function method(mixed $a) {}
}

class Bar extends Foo
{
public function method(bool $a) {}
}

?>
--EXPECTF--
Fatal error: Declaration of Bar::method(bool $a) must be compatible with Foo::method(mixed $a) in %s on line %d
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Test that a mixed parameter type can't be overridden by a nullable built-in type
--FILE--
<?php

class Foo
{
public function method(mixed $a) {}
}

class Bar extends Foo
{
public function method(?int $a) {}
}

?>
--EXPECTF--
Fatal error: Declaration of Bar::method(?int $a) must be compatible with Foo::method(mixed $a) in %s on line %d
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Test that a mixed parameter type can't be overridden by a union of all built-in types
--FILE--
<?php

class Foo
{
public function method(mixed $a) {}
}

class Bar extends Foo
{
public function method(bool|int|float|string|array|object|null $a) {}
}

?>
--EXPECTF--
Fatal error: Declaration of Bar::method(object|array|string|int|float|bool|null $a) must be compatible with Foo::method(mixed $a) in %s on line %d
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Test that a mixed parameter type can't be overridden by a union type of classes
--FILE--
<?php

class Foo
{
public function method(mixed $a) {}
}

class Bar extends Foo
{
public function method(stdClass|Foo $a) {}
}

?>
--EXPECTF--
Fatal error: Declaration of Bar::method(stdClass|Foo $a) must be compatible with Foo::method(mixed $a) in %s on line %d
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Test that a mixed parameter type supports invariance
--FILE--
<?php

class Foo
{
public function method(mixed $a) {}
}

class Bar extends Foo
{
public function method(mixed $a) {}
}

?>
--EXPECT--
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Test that a mixed parameter type can be overridden by no type
--FILE--
<?php

class Foo
{
public function method(mixed $a) {}
}

class Bar extends Foo
{
public function method($a) {}
}

?>
--EXPECT--
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Test that a parameter of no type can be overridden by the mixed type
--FILE--
<?php

class Foo
{
public function method($a) {}
}

class Bar extends Foo
{
public function method(mixed $a) {}
}

?>
--EXPECT--
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Test that a parameter of a built-in type can be overridden by the mixed type
--FILE--
<?php

class Foo
{
public function method(int $a) {}
}

class Bar extends Foo
{
public function method(mixed $a) {}
}

?>
--EXPECT--
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Test that a parameter of a nullable built-in type can be overridden by the mixed type
--FILE--
<?php

class Foo
{
public function method(?int $a) {}
}

class Bar extends Foo
{
public function method(mixed $a) {}
}

?>
--EXPECT--
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Test that a parameter of a union of all built-in types can be overridden by the mixed type
--FILE--
<?php

class Foo
{
public function method(bool|int|float|string|array|object|null $a) {}
}

class Bar extends Foo
{
public function method(mixed $a) {}
}

?>
--EXPECT--
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Test that a parameter of a union type of classes can be overridden by the mixed type
--FILE--
<?php

class Foo
{
public function method(stdClass|Foo $a) {}
}

class Bar extends Foo
{
public function method(mixed $a) {}
}

?>
--EXPECT--
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Test that a property of mixed type can't be overridden by a property of a built-in type
--FILE--
<?php

class Foo
{
public mixed $property1;
}

class Bar extends Foo
{
public int $property1;
}

?>
--EXPECTF--
Fatal error: Type of Bar::$property1 must be mixed (as in class Foo) in %s on line %d
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Test that a property of mixed type can't be overridden by a property of class type
--FILE--
<?php

class Foo
{
public mixed $property1;
}

class Bar extends Foo
{
public stdClass $property1;
}

?>
--EXPECTF--
Fatal error: Type of Bar::$property1 must be mixed (as in class Foo) in %s on line %d
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Test that a property of mixed type can't be overridden by an untyped property
--FILE--
<?php

class Foo
{
public mixed $property1;
}

class Bar extends Foo
{
public $property1;
}

?>
--EXPECTF--
Fatal error: Type of Bar::$property1 must be mixed (as in class Foo) in %s on line %d
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Test that a property of mixed type can't be overridden by a property of a union type
--FILE--
<?php

class Foo
{
public mixed $property1;
}

class Bar extends Foo
{
public bool|int|float|string|array|object|null $property1;
}

?>
--EXPECTF--
Fatal error: Type of Bar::$property1 must be mixed (as in class Foo) in %s on line %d
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Test that a property of a built-in type can't be overridden by a property of mixed type
--FILE--
<?php

class Foo
{
public int $property1;
}

class Bar extends Foo
{
public mixed $property1;
}

?>
--EXPECTF--
Fatal error: Type of Bar::$property1 must be int (as in class Foo) in %s on line %d
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Test that a property of class type can't be overridden by a property of mixed type
--FILE--
<?php

class Foo
{
public stdClass $property1;
}

class Bar extends Foo
{
public mixed $property1;
}

?>
--EXPECTF--
Fatal error: Type of Bar::$property1 must be stdClass (as in class Foo) in %s on line %d
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Test that an untyped property can't be overridden by a property of mixed type
--FILE--
<?php

class Foo
{
public $property1;
}

class Bar extends Foo
{
public mixed $property1;
}

?>
--EXPECTF--
Fatal error: Type of Bar::$property1 must not be defined (as in class Foo) in %s on line %d
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Test that a property of a union type can't be overridden by a property of mixed type
--FILE--
<?php

class Foo
{
public bool|int|float|string|array|object|null $property1;
}

class Bar extends Foo
{
public mixed $property1;
}

?>
--EXPECTF--
Fatal error: Type of Bar::$property1 must be object|array|string|int|float|bool|null (as in class Foo) in %s on line %d
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Test that a property of mixed property type can be overridden by a property of mixed type
--FILE--
<?php

class Foo
{
public mixed $property1;
}

class Bar extends Foo
{
public mixed $property1;
}

?>
--EXPECT--
Loading