Skip to content

Commit

Permalink
Remove internal usage of SplFileInfo::_bad_state_ex() method
Browse files Browse the repository at this point in the history
Use standard VM handling instead

Deprecate the method
  • Loading branch information
Girgias committed Jun 8, 2022
1 parent 89688b1 commit 65da53f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 8 deletions.
2 changes: 2 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ PHP 8.2 UPGRADE NOTES
separate, built-in implementations of all of them; for example, UUencoded
data can be handled using convert_uuencode/convert_uudecode.

- SPL:
. The SplFileInfo::_bad_state_ex() internal method has been deprecated.
========================================
5. Changed Functions
========================================
Expand Down
8 changes: 3 additions & 5 deletions ext/spl/spl_directory.c
Original file line number Diff line number Diff line change
Expand Up @@ -693,11 +693,8 @@ zend_function *spl_filesystem_object_get_method_check(zend_object **object, zend
spl_filesystem_object *fsobj = spl_filesystem_from_obj(*object);

if (fsobj->u.dir.dirp == NULL && fsobj->orig_path == NULL) {
zend_function *func;
zend_string *tmp = zend_string_init("_bad_state_ex", sizeof("_bad_state_ex") - 1, 0);
func = zend_std_get_method(object, tmp, NULL);
zend_string_release_ex(tmp, 0);
return func;
zend_throw_error(NULL, "The parent constructor was not called: the object is in an invalid state");
return NULL;
}

return zend_std_get_method(object, method, key);
Expand Down Expand Up @@ -1403,6 +1400,7 @@ PHP_METHOD(SplFileInfo, _bad_state_ex)
RETURN_THROWS();
}
zend_throw_error(NULL, "The parent constructor was not called: the object is in an invalid state");
RETURN_THROWS();
}
/* }}} */

Expand Down
5 changes: 4 additions & 1 deletion ext/spl/spl_directory.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ public function __toString(): string {}
/** @tentative-return-type */
public function __debugInfo(): array {}

/** @tentative-return-type */
/**
* @deprecated
* @tentative-return-type
*/
final public function _bad_state_ex(): void {}
}

Expand Down
4 changes: 2 additions & 2 deletions ext/spl/spl_directory_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions ext/spl/tests/gh8318.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
--TEST--
GH-8318 (SplFileObject useless call to an internal method for erroring)
--FILE--
<?php
class bug8318 extends \SplFileObject
{
public function __construct()
{
}

public function fpassthru(): int
{
return 0;
}
}

$cl = new bug8318;
try {
$cl->fpassthru();
} catch (\Error $e) {
var_dump($e);
}
?>
--EXPECTF--
object(Error)#2 (7) {
["message":protected]=>
string(72) "The parent constructor was not called: the object is in an invalid state"
["string":"Error":private]=>
string(0) ""
["code":protected]=>
int(0)
["file":protected]=>
string(50) "%s"
["line":protected]=>
int(16)
["trace":"Error":private]=>
array(0) {
}
["previous":"Error":private]=>
NULL
}

0 comments on commit 65da53f

Please sign in to comment.