-
Notifications
You must be signed in to change notification settings - Fork 7.9k
ext/standard/dir.c: Directory class should behave like other opaque objects #15886
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
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--TEST-- | ||
Cannot serialize instance of Directory class constructed via Reflection. | ||
--FILE-- | ||
<?php | ||
|
||
$d = dir(__DIR__); | ||
try { | ||
$cloned = clone $d; | ||
$cloned_files = []; | ||
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. Given that the error is going to come from the 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. Same remark. |
||
while ($row = $cloned->read()){ | ||
$cloned_files[] = $row; | ||
} | ||
var_dump(count($cloned_files)); | ||
echo "Using original object:\n"; | ||
$original_files = []; | ||
while ($row = $d->read()){ | ||
$original_files[] = $row; | ||
} | ||
var_dump(count($original_files)); | ||
} catch (\Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
Error: Trying to clone an uncloneable object of class Directory |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--TEST-- | ||
Cannot directly instantiate Directory class. | ||
--FILE-- | ||
<?php | ||
|
||
try { | ||
$d = new Directory(); | ||
var_dump($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. in the same vein, I suggest removing the 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. The point is to have an output in case it was able to be initialized, moreover, this was introduced in a prior commit to see the difference in behaviour. |
||
} catch (\Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
Error: Cannot directly construct Directory, use dir() instead |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--TEST-- | ||
Cannot serialize instance of Directory class constructed via Reflection. | ||
--FILE-- | ||
<?php | ||
|
||
$d = dir(__DIR__); | ||
try { | ||
$s = serialize($d); | ||
var_dump($s); | ||
} catch (\Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
Exception: Serialization of 'Directory' is not allowed |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--TEST-- | ||
Changing Directory::$handle property | ||
--FILE-- | ||
<?php | ||
|
||
$d = dir(__DIR__); | ||
try { | ||
$d->handle = "Havoc!"; | ||
} catch (\Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
var_dump($d->handle); | ||
|
||
try { | ||
unset($d->handle); | ||
} catch (\Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
var_dump($d->handle); | ||
|
||
?> | ||
--EXPECTF-- | ||
Error: Cannot modify readonly property Directory::$handle | ||
resource(%d) of type (stream) | ||
Error: Cannot unset readonly property Directory::$handle | ||
resource(%d) of type (stream) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--TEST-- | ||
Changing Directory::$handle property | ||
--FILE-- | ||
<?php | ||
|
||
$d = dir(__DIR__); | ||
try { | ||
$d->path = "Havoc!"; | ||
} catch (\Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
var_dump($d->path == __DIR__); | ||
|
||
try { | ||
unset($d->path); | ||
} catch (\Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
var_dump($d->path == __DIR__); | ||
|
||
?> | ||
--EXPECTF-- | ||
Error: Cannot modify readonly property Directory::$path | ||
bool(true) | ||
Error: Cannot unset readonly property Directory::$path | ||
bool(true) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--TEST-- | ||
Cannot use instance of Directory class constructed via Reflection. | ||
--FILE-- | ||
<?php | ||
|
||
$rc = new ReflectionClass("Directory"); | ||
var_dump($rc->isInstantiable()); | ||
try { | ||
$d = $rc->newInstanceWithoutConstructor(); | ||
} catch (\Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
var_dump($d); | ||
try { | ||
var_dump($d->read()); | ||
} catch (\Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
bool(true) | ||
object(Directory)#2 (0) { | ||
["path"]=> | ||
uninitialized(string) | ||
["handle"]=> | ||
uninitialized(mixed) | ||
} | ||
Error: Unable to find my handle property |
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.
Because the class is now final, I suppose the return types of the methods no longer need to be tentative?
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.
Actually a good point, will fix this.