mirror of
https://github.com/php/php-src.git
synced 2025-08-15 13:38:49 +02:00
ext/standard/dir.c: Directory class should behave like other resource objects
This commit is contained in:
parent
76f6592d12
commit
0640fbab60
7 changed files with 25 additions and 15 deletions
|
@ -48,10 +48,17 @@ php_dir_globals dir_globals;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static zend_class_entry *dir_class_entry_ptr;
|
static zend_class_entry *dir_class_entry_ptr;
|
||||||
|
static zend_object_handlers dir_class_object_handlers;
|
||||||
|
|
||||||
#define Z_DIRECTORY_PATH_P(zv) OBJ_PROP_NUM(Z_OBJ_P(zv), 0)
|
#define Z_DIRECTORY_PATH_P(zv) OBJ_PROP_NUM(Z_OBJ_P(zv), 0)
|
||||||
#define Z_DIRECTORY_HANDLE_P(zv) OBJ_PROP_NUM(Z_OBJ_P(zv), 1)
|
#define Z_DIRECTORY_HANDLE_P(zv) OBJ_PROP_NUM(Z_OBJ_P(zv), 1)
|
||||||
|
|
||||||
|
static zend_function *dir_class_get_constructor(zend_object *object)
|
||||||
|
{
|
||||||
|
zend_throw_error(NULL, "Cannot directly construct Directory, use dir() instead");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
#define FETCH_DIRP() \
|
#define FETCH_DIRP() \
|
||||||
myself = getThis(); \
|
myself = getThis(); \
|
||||||
if (!myself) { \
|
if (!myself) { \
|
||||||
|
@ -115,6 +122,12 @@ PHP_MINIT_FUNCTION(dir)
|
||||||
register_dir_symbols(module_number);
|
register_dir_symbols(module_number);
|
||||||
|
|
||||||
dir_class_entry_ptr = register_class_Directory();
|
dir_class_entry_ptr = register_class_Directory();
|
||||||
|
dir_class_entry_ptr->default_object_handlers = &dir_class_object_handlers;
|
||||||
|
|
||||||
|
memcpy(&dir_class_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
|
||||||
|
dir_class_object_handlers.get_constructor = dir_class_get_constructor;
|
||||||
|
dir_class_object_handlers.clone_obj = NULL;
|
||||||
|
dir_class_object_handlers.compare = zend_objects_not_comparable;
|
||||||
|
|
||||||
#ifdef ZTS
|
#ifdef ZTS
|
||||||
ts_allocate_id(&dir_globals_id, sizeof(php_dir_globals), NULL, NULL);
|
ts_allocate_id(&dir_globals_id, sizeof(php_dir_globals), NULL, NULL);
|
||||||
|
|
|
@ -87,7 +87,11 @@ const SCANDIR_SORT_DESCENDING = UNKNOWN;
|
||||||
*/
|
*/
|
||||||
const SCANDIR_SORT_NONE = UNKNOWN;
|
const SCANDIR_SORT_NONE = UNKNOWN;
|
||||||
|
|
||||||
class Directory
|
/**
|
||||||
|
* @strict-properties
|
||||||
|
* @not-serializable
|
||||||
|
*/
|
||||||
|
final class Directory
|
||||||
{
|
{
|
||||||
public readonly string $path;
|
public readonly string $path;
|
||||||
|
|
||||||
|
|
4
ext/standard/dir_arginfo.h
generated
4
ext/standard/dir_arginfo.h
generated
|
@ -1,5 +1,5 @@
|
||||||
/* This is a generated file, edit the .stub.php file instead.
|
/* This is a generated file, edit the .stub.php file instead.
|
||||||
* Stub hash: 4b0f093770ff9a6cad9db033e0b62b412408b937 */
|
* Stub hash: 3fdc106d96cf9e728886637eecdb43c2552b174f */
|
||||||
|
|
||||||
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_Directory_close, 0, 0, IS_VOID, 0)
|
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_Directory_close, 0, 0, IS_VOID, 0)
|
||||||
ZEND_END_ARG_INFO()
|
ZEND_END_ARG_INFO()
|
||||||
|
@ -58,7 +58,7 @@ static zend_class_entry *register_class_Directory(void)
|
||||||
zend_class_entry ce, *class_entry;
|
zend_class_entry ce, *class_entry;
|
||||||
|
|
||||||
INIT_CLASS_ENTRY(ce, "Directory", class_Directory_methods);
|
INIT_CLASS_ENTRY(ce, "Directory", class_Directory_methods);
|
||||||
class_entry = zend_register_internal_class_with_flags(&ce, NULL, 0);
|
class_entry = zend_register_internal_class_with_flags(&ce, NULL, ZEND_ACC_FINAL|ZEND_ACC_NO_DYNAMIC_PROPERTIES|ZEND_ACC_NOT_SERIALIZABLE);
|
||||||
|
|
||||||
zval property_path_default_value;
|
zval property_path_default_value;
|
||||||
ZVAL_UNDEF(&property_path_default_value);
|
ZVAL_UNDEF(&property_path_default_value);
|
||||||
|
|
|
@ -23,6 +23,4 @@ try {
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
int(17)
|
Error: Trying to clone an uncloneable object of class Directory
|
||||||
Using original object:
|
|
||||||
int(0)
|
|
||||||
|
|
|
@ -12,9 +12,4 @@ try {
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
object(Directory)#1 (0) {
|
Error: Cannot directly construct Directory, use dir() instead
|
||||||
["path"]=>
|
|
||||||
uninitialized(string)
|
|
||||||
["handle"]=>
|
|
||||||
uninitialized(mixed)
|
|
||||||
}
|
|
||||||
|
|
|
@ -12,5 +12,5 @@ try {
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--EXPECT--
|
||||||
string(%d) "O:9:"Directory":2:{s:4:"path";s:%d:"%s";s:6:"handle";i:%d;}"
|
Exception: Serialization of 'Directory' is not allowed
|
||||||
|
|
|
@ -14,7 +14,7 @@ echo $rc;
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
Structure of Directory class:
|
Structure of Directory class:
|
||||||
Class [ <internal%s> class Directory ] {
|
Class [ <internal%s> final class Directory ] {
|
||||||
|
|
||||||
- Constants [0] {
|
- Constants [0] {
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue