-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Covariant Returns and Contravariant Parameters #3712
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
Changes from all commits
6819342
274ad54
e1d8606
c318691
00d9439
7316918
41fa626
131ec50
c1b0f6c
ea9497a
43d79a1
3dc2312
6b9394b
6f3dfa2
7e75361
89dd30a
e27890f
93aab70
acd3ec6
6be654a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?php | ||
|
||
class Foo {} | ||
class_alias('Foo', 'Bar'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--TEST-- | ||
Aliases during inheritance type checks affected by opcache | ||
--INI-- | ||
opcache.enable=1 | ||
opcache.enable_cli=1 | ||
opcache.optimization_level=-1 | ||
--SKIPIF-- | ||
<?php if (!extension_loaded('Zend OPcache') || php_sapi_name() != "cli") die("skip CLI only"); ?> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Off topic: The second part of this condition, when does it happen? I mean, can we run the tests without been via the CLI? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @carusogabriel run-tests can actually execute with php-cgi aswell, see: https://github.com/php/php-src/blob/master/run-tests.php#L123 and below and below :) |
||
--FILE-- | ||
<?php | ||
require __DIR__ . "/bug76451.inc"; | ||
|
||
class A { | ||
public function test(Foo $foo) {} | ||
} | ||
class B extends A { | ||
public function test(Bar $foo) {} | ||
} | ||
?> | ||
--EXPECT-- |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,6 @@ namespace Foo\Bar { | |
} | ||
?> | ||
--EXPECTF-- | ||
Fatal error: parent::class cannot be used for compile-time class name resolution in %s on line %d | ||
Deprecated: Cannot use "parent" without a parent class in %s on line %d | ||
|
||
Fatal error: Cannot use "parent" without a parent class in %s on line %d | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally, I would separate parent::class into a different patch. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--TEST-- | ||
Using "parent" in class without parent results in compile-time error | ||
--FILE-- | ||
<?php | ||
class InvalidClass { | ||
function method(parent $p) {} | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Deprecated: Cannot use "parent" without a parent class in %s on line %d |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--TEST-- | ||
Using "parent" in class without parent results in compile-time error | ||
--FILE-- | ||
<?php | ||
class InvalidClass { | ||
function method(): parent {} | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Deprecated: Cannot use "parent" without a parent class in %s on line %d |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--TEST-- | ||
Using "parent" in class without parent results in compile-time error | ||
--FILE-- | ||
<?php | ||
class InvalidClass { | ||
function method() { | ||
echo parent::class; | ||
} | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Deprecated: Cannot use "parent" without a parent class in %s on line %d |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--TEST-- | ||
Using "parent" in class without parent results in compile-time error | ||
--FILE-- | ||
<?php | ||
$obj = new class() { | ||
function method() { | ||
echo parent::class; | ||
} | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Deprecated: Cannot use "parent" without a parent class in %s on line %d |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--TEST-- | ||
Using "parent" in class without parent results in compile-time error | ||
--FILE-- | ||
<?php | ||
class InvalidClass { | ||
function method() { | ||
$obj = new class() { | ||
function method() { | ||
echo parent::class; | ||
} | ||
}; | ||
} | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Deprecated: Cannot use "parent" without a parent class in %s on line %d |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--TEST-- | ||
Testing object's variance in inheritance | ||
--FILE-- | ||
<?php | ||
|
||
interface I1 { | ||
function method1(I1 $o): object; | ||
} | ||
interface I2 extends I1 { | ||
function method1(object $o): I1; | ||
} | ||
final class C1 implements I2 { | ||
function method1($o = null): self { | ||
return $this; | ||
} | ||
} | ||
|
||
$o = new C1(); | ||
echo get_class($o->method1()); | ||
?> | ||
--EXPECT-- | ||
C1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--TEST-- | ||
Using parent does not create compile-time warnings | ||
--FILE-- | ||
<?php | ||
|
||
trait P { | ||
public function m(parent $arg): parent { | ||
return $arg; | ||
} | ||
} | ||
|
||
class A {} | ||
|
||
class B extends A { | ||
use P; | ||
} | ||
|
||
$b = new B(); | ||
$a = $b->m(new A()); | ||
|
||
print "OK\n"; | ||
|
||
?> | ||
--EXPECT-- | ||
OK | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose, you removed this, because of some compatibility break, but you didn't reflect this in RFC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See this comment on bugs.php.net:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just don't make unrelated "improvements" in PHPT tests, because they look suspicious, and require reviewers to verify them. Better, commit these chunks separately.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are not unrelated. The unused method
A::initialize
has erroneousparent::
usage, which this includes. I know you said you would have preferred that to be a different patch, but the code that deals withparent
is needed for resolving variance correctly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to add compile-time warning. This would clearly explain the change in behavior, and its correctness.