-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
179 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--TEST-- | ||
Testing class_alias() | ||
--FILE-- | ||
<?php | ||
|
||
class foo { } | ||
|
||
class_alias('foo', 'bar'); | ||
|
||
$a = new foo; | ||
$b = new bar; | ||
|
||
var_dump($a == $b, $a === $b); | ||
var_dump($a instanceof $b); | ||
|
||
var_dump($a instanceof foo); | ||
var_dump($a instanceof bar); | ||
|
||
var_dump($b instanceof foo); | ||
var_dump($b instanceof bar); | ||
|
||
?> | ||
--EXPECT-- | ||
bool(true) | ||
bool(false) | ||
bool(true) | ||
bool(true) | ||
bool(true) | ||
bool(true) | ||
bool(true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--TEST-- | ||
Trying redeclare class with class_alias() | ||
--FILE-- | ||
<?php | ||
|
||
class foo { } | ||
|
||
class_alias('foo', 'FOO'); | ||
|
||
?> | ||
--EXPECTF-- | ||
Warning: Cannot redeclare class FOO in %s on line %d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--TEST-- | ||
Testing declaration of alias to 'static' | ||
--FILE-- | ||
<?php | ||
|
||
class bar { | ||
} | ||
|
||
class foo { | ||
public function test() { | ||
class_alias('bar', 'static'); | ||
return new static; | ||
} | ||
} | ||
|
||
$a = new foo; | ||
var_dump($a->test()); | ||
|
||
?> | ||
--EXPECTF-- | ||
object(foo)#%d (0) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--TEST-- | ||
Testing creation of alias using an existing interface name | ||
--FILE-- | ||
<?php | ||
|
||
class foo { } | ||
|
||
interface test { } | ||
|
||
|
||
class_alias('foo', 'test'); | ||
|
||
?> | ||
--EXPECTF-- | ||
Warning: Cannot redeclare class test in %s on line %d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--TEST-- | ||
Testing static call method using the original class name | ||
--FILE-- | ||
<?php | ||
|
||
class foo { | ||
static public function msg() { | ||
print "hello\n"; | ||
} | ||
} | ||
|
||
interface test { } | ||
|
||
|
||
class_alias('foo', 'baz'); | ||
|
||
class bar extends baz { | ||
public function __construct() { | ||
foo::msg(); | ||
} | ||
} | ||
|
||
new bar; | ||
|
||
?> | ||
--EXPECT-- | ||
hello |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--TEST-- | ||
Testing creation of alias to an internal class | ||
--FILE-- | ||
<?php | ||
|
||
class_alias('stdclass', 'foo'); | ||
|
||
?> | ||
--EXPECTF-- | ||
Warning: First argument of class_alias() must be a name of user defined class in %s on line %d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--TEST-- | ||
Testing class_alias() using autoload | ||
--FILE-- | ||
<?php | ||
|
||
function __autoload($a) { | ||
class foo { } | ||
} | ||
|
||
class_alias('foo', 'bar', 1); | ||
|
||
var_dump(new foo, new bar); | ||
|
||
?> | ||
--EXPECTF-- | ||
object(foo)#%d (0) { | ||
} | ||
object(foo)#%d (0) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--TEST-- | ||
Testing class_alias() with abstract class using an arbitrary class name as alias | ||
--FILE-- | ||
<?php | ||
|
||
abstract class foo { } | ||
|
||
class_alias('foo', "\0"); | ||
|
||
$a = "\0"; | ||
|
||
new $a; | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Cannot instantiate abstract class foo in %s on line %d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--TEST-- | ||
Testing interface declaration using the original and alias class name | ||
--FILE-- | ||
<?php | ||
|
||
interface a { } | ||
|
||
class_alias('a', 'b'); | ||
|
||
interface c extends a, b { } | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Class c cannot implement previously implemented interface a in %s on line %d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--TEST-- | ||
Trying use an existing alias name in class declaration | ||
--FILE-- | ||
<?php | ||
|
||
interface a { } | ||
|
||
class_alias('a', 'b'); | ||
|
||
class b { } | ||
|
||
?> | ||
--EXPECTF-- | ||
Warning: Cannot redeclare class b in %s on line %d |