Skip to content

Commit f91f000

Browse files
committed
Address code review comments
1 parent 7dcd191 commit f91f000

File tree

10 files changed

+60
-81
lines changed

10 files changed

+60
-81
lines changed

ext/ffi/ffi.stub.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public static function new($type, bool $owned = true, bool $persistent = false):
1717
public static function free(FFI\CData $ptr): void {}
1818

1919
/**
20-
* @param FFI\CData $ptr
20+
* @param FFI\CType|string $type
21+
* @param FFI\CData|string|int|null $ptr
2122
* @prefer-ref $ptr
2223
*/
2324
public static function cast(FFI\CType|string $type, $ptr): ?FFI\CData {}

ext/ffi/ffi_arginfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: fc700bbcced0689e4e5363e4003a84d162258555 */
2+
* Stub hash: c66984b2626207c5c80b1dbe48d23991a15d136c */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_FFI_cdef, 0, 0, FFI, 0)
55
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, code, IS_STRING, 0, "\"\"")

ext/pdo/pdo_stmt.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class PDOStatement implements IteratorAggregate
66
{
77
/** @return bool */
8-
public function bindColumn(int|string $column, mixed &$param, int $type = 0, int $maxlen = 0, mixed $driverdata = null) {}
8+
public function bindColumn(string|int $column, mixed &$param, int $type = 0, int $maxlen = 0, mixed $driverdata = null) {}
99

1010
/** @return bool */
1111
public function bindParam(string|int $parameter, mixed &$param, int $type = PDO::PARAM_STR, int $maxlen = 0, mixed $driverdata = null) {}

ext/pdo/pdo_stmt_arginfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 08beb825ecbd1b96aac4e71563ccb55a7e5c1be2 */
2+
* Stub hash: d64c75660cfc44b582e7dcc20c4ce22e8e0848e1 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDOStatement_bindColumn, 0, 0, 2)
5-
ZEND_ARG_TYPE_MASK(0, column, MAY_BE_LONG|MAY_BE_STRING, NULL)
5+
ZEND_ARG_TYPE_MASK(0, column, MAY_BE_STRING|MAY_BE_LONG, NULL)
66
ZEND_ARG_TYPE_INFO(1, param, IS_MIXED, 0)
77
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, type, IS_LONG, 0, "0")
88
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, maxlen, IS_LONG, 0, "0")

ext/soap/soap.c

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ PHP_METHOD(SoapHeader, __construct)
543543
zval *data = NULL;
544544
zend_string *actor_str = NULL;
545545
zend_long actor_long;
546-
zend_bool actor_long_is_null = 1;
546+
zend_bool actor_is_null = 1;
547547
char *name, *ns;
548548
size_t name_len, ns_len;
549549
zend_bool must_understand = 0;
@@ -555,7 +555,7 @@ PHP_METHOD(SoapHeader, __construct)
555555
Z_PARAM_OPTIONAL
556556
Z_PARAM_ZVAL(data)
557557
Z_PARAM_BOOL(must_understand)
558-
Z_PARAM_STR_OR_LONG_OR_NULL(actor_str, actor_long, actor_long_is_null)
558+
Z_PARAM_STR_OR_LONG_OR_NULL(actor_str, actor_long, actor_is_null)
559559
ZEND_PARSE_PARAMETERS_END();
560560

561561
if (ns_len == 0) {
@@ -575,12 +575,14 @@ PHP_METHOD(SoapHeader, __construct)
575575
}
576576
add_property_bool(this_ptr, "mustUnderstand", must_understand);
577577

578-
if (!actor_long_is_null && (actor_long == SOAP_ACTOR_NEXT || actor_long == SOAP_ACTOR_NONE || actor_long == SOAP_ACTOR_UNLIMATERECEIVER)) {
579-
add_property_long(this_ptr, "actor", actor_long);
580-
} else if (actor_str && ZSTR_LEN(actor_str) > 2) {
581-
add_property_stringl(this_ptr, "actor", ZSTR_VAL(actor_str), ZSTR_LEN(actor_str));
582-
} else if (!actor_long_is_null || actor_str) {
583-
php_error_docref(NULL, E_WARNING, "Invalid actor");
578+
if (!actor_is_null) {
579+
if (actor_str && ZSTR_LEN(actor_str) > 2) {
580+
add_property_stringl(this_ptr, "actor", ZSTR_VAL(actor_str), ZSTR_LEN(actor_str));
581+
} else if ((actor_long == SOAP_ACTOR_NEXT || actor_long == SOAP_ACTOR_NONE || actor_long == SOAP_ACTOR_UNLIMATERECEIVER)) {
582+
add_property_long(this_ptr, "actor", actor_long);
583+
} else {
584+
php_error_docref(NULL, E_WARNING, "Invalid actor");
585+
}
584586
}
585587
}
586588
/* }}} */
@@ -607,23 +609,19 @@ PHP_METHOD(SoapFault, __construct)
607609
if (code_str) {
608610
fault_code = ZSTR_VAL(code_str);
609611
fault_code_len = ZSTR_LEN(code_str);
610-
} else if (code_ht && zend_hash_num_elements(code_ht) == 2) {
611-
zval *t_ns = zend_hash_index_find(code_ht, 0);
612-
zval *t_code = zend_hash_index_find(code_ht, 1);
613-
if (t_ns && t_code && Z_TYPE_P(t_ns) == IS_STRING && Z_TYPE_P(t_code) == IS_STRING) {
614-
fault_code_ns = Z_STRVAL_P(t_ns);
615-
fault_code = Z_STRVAL_P(t_code);
616-
fault_code_len = Z_STRLEN_P(t_code);
617-
} else {
618-
php_error_docref(NULL, E_WARNING, "Invalid fault code");
619-
return;
612+
} else if (code_ht) {
613+
if (zend_hash_num_elements(code_ht) == 2) {
614+
zval *t_ns = zend_hash_index_find(code_ht, 0);
615+
zval *t_code = zend_hash_index_find(code_ht, 1);
616+
if (t_ns && t_code && Z_TYPE_P(t_ns) == IS_STRING && Z_TYPE_P(t_code) == IS_STRING) {
617+
fault_code_ns = Z_STRVAL_P(t_ns);
618+
fault_code = Z_STRVAL_P(t_code);
619+
fault_code_len = Z_STRLEN_P(t_code);
620+
}
620621
}
621-
} else if (code_str || code_ht) {
622-
php_error_docref(NULL, E_WARNING, "Invalid fault code");
623-
return;
624622
}
625623

626-
if (fault_code != NULL && fault_code_len == 0) {
624+
if ((code_str || code_ht) && (fault_code == NULL || fault_code_len == 0)) {
627625
php_error_docref(NULL, E_WARNING, "Invalid fault code");
628626
return;
629627
}

ext/standard/basic_functions.stub.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -939,18 +939,14 @@ function stat(string $filename): array|false {}
939939

940940
function lstat(string $filename): array|false {}
941941

942-
/** @param string|int $user */
943-
function chown(string $filename, $user): bool {}
942+
function chown(string $filename, string|int $user): bool {}
944943

945-
/** @param string|int $group */
946-
function chgrp(string $filename, $group): bool {}
944+
function chgrp(string $filename, string|int $group): bool {}
947945

948946
#if HAVE_LCHOWN
949-
/** @param string|int $user */
950-
function lchown(string $filename, $user): bool {}
947+
function lchown(string $filename, string|int $user): bool {}
951948

952-
/** @param string|int $group */
953-
function lchgrp(string $filename, $group): bool {}
949+
function lchgrp(string $filename, string|int $group): bool {}
954950
#endif
955951

956952
function chmod(string $filename, int $mode): bool {}

ext/standard/basic_functions_arginfo.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,25 +1414,25 @@ ZEND_END_ARG_INFO()
14141414

14151415
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_chown, 0, 2, _IS_BOOL, 0)
14161416
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
1417-
ZEND_ARG_INFO(0, user)
1417+
ZEND_ARG_TYPE_MASK(0, user, MAY_BE_STRING|MAY_BE_LONG, NULL)
14181418
ZEND_END_ARG_INFO()
14191419

14201420
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_chgrp, 0, 2, _IS_BOOL, 0)
14211421
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
1422-
ZEND_ARG_INFO(0, group)
1422+
ZEND_ARG_TYPE_MASK(0, group, MAY_BE_STRING|MAY_BE_LONG, NULL)
14231423
ZEND_END_ARG_INFO()
14241424

14251425
#if HAVE_LCHOWN
14261426
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_lchown, 0, 2, _IS_BOOL, 0)
14271427
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
1428-
ZEND_ARG_INFO(0, user)
1428+
ZEND_ARG_TYPE_MASK(0, user, MAY_BE_STRING|MAY_BE_LONG, NULL)
14291429
ZEND_END_ARG_INFO()
14301430
#endif
14311431

14321432
#if HAVE_LCHOWN
14331433
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_lchgrp, 0, 2, _IS_BOOL, 0)
14341434
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
1435-
ZEND_ARG_INFO(0, group)
1435+
ZEND_ARG_TYPE_MASK(0, group, MAY_BE_STRING|MAY_BE_LONG, NULL)
14361436
ZEND_END_ARG_INFO()
14371437
#endif
14381438

ext/standard/filestat.c

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,8 @@ static void php_do_chgrp(INTERNAL_FUNCTION_PARAMETERS, int do_lchgrp) /* {{{ */
327327
{
328328
char *filename;
329329
size_t filename_len;
330-
zval *group;
330+
zend_string *group_str;
331+
zend_long group_long;
331332
#if !defined(WINDOWS)
332333
gid_t gid;
333334
int ret;
@@ -336,24 +337,22 @@ static void php_do_chgrp(INTERNAL_FUNCTION_PARAMETERS, int do_lchgrp) /* {{{ */
336337

337338
ZEND_PARSE_PARAMETERS_START(2, 2)
338339
Z_PARAM_PATH(filename, filename_len)
339-
Z_PARAM_ZVAL(group)
340+
Z_PARAM_STR_OR_LONG(group_str, group_long)
340341
ZEND_PARSE_PARAMETERS_END();
341342

342343
wrapper = php_stream_locate_url_wrapper(filename, NULL, 0);
343344
if(wrapper != &php_plain_files_wrapper || strncasecmp("file://", filename, 7) == 0) {
344345
if(wrapper && wrapper->wops->stream_metadata) {
345346
int option;
346347
void *value;
347-
if (Z_TYPE_P(group) == IS_LONG) {
348-
option = PHP_STREAM_META_GROUP;
349-
value = &Z_LVAL_P(group);
350-
} else if (Z_TYPE_P(group) == IS_STRING) {
348+
if (group_str) {
351349
option = PHP_STREAM_META_GROUP_NAME;
352-
value = Z_STRVAL_P(group);
350+
value = group_str;
353351
} else {
354-
zend_argument_type_error(2, "must be of type string|int, %s given", zend_zval_type_name(group));
355-
RETURN_THROWS();
352+
option = PHP_STREAM_META_GROUP;
353+
value = &group_long;
356354
}
355+
357356
if(wrapper->wops->stream_metadata(wrapper, filename, option, value, NULL)) {
358357
RETURN_TRUE;
359358
} else {
@@ -372,16 +371,13 @@ static void php_do_chgrp(INTERNAL_FUNCTION_PARAMETERS, int do_lchgrp) /* {{{ */
372371
/* We have no native chgrp on Windows, nothing left to do if stream doesn't have own implementation */
373372
RETURN_FALSE;
374373
#else
375-
if (Z_TYPE_P(group) == IS_LONG) {
376-
gid = (gid_t)Z_LVAL_P(group);
377-
} else if (Z_TYPE_P(group) == IS_STRING) {
378-
if(php_get_gid_by_name(Z_STRVAL_P(group), &gid) != SUCCESS) {
379-
php_error_docref(NULL, E_WARNING, "Unable to find gid for %s", Z_STRVAL_P(group));
374+
if (group_str) {
375+
if (php_get_gid_by_name(ZSTR_VAL(group_str), &gid) != SUCCESS) {
376+
php_error_docref(NULL, E_WARNING, "Unable to find gid for %s", ZSTR_VAL(group_str));
380377
RETURN_FALSE;
381378
}
382379
} else {
383-
zend_argument_type_error(2, "must be of type string|int, %s given", zend_zval_type_name(group));
384-
RETURN_THROWS();
380+
gid = (gid_t) group_long;
385381
}
386382

387383
/* Check the basedir */
@@ -416,11 +412,7 @@ PHP_FUNCTION(chgrp)
416412
#if HAVE_LCHOWN
417413
PHP_FUNCTION(lchgrp)
418414
{
419-
# if !defined(WINDOWS)
420415
php_do_chgrp(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
421-
# else
422-
RETURN_FALSE;
423-
# endif
424416
}
425417
#endif
426418
/* }}} */
@@ -461,7 +453,8 @@ static void php_do_chown(INTERNAL_FUNCTION_PARAMETERS, int do_lchown) /* {{{ */
461453
{
462454
char *filename;
463455
size_t filename_len;
464-
zval *user;
456+
zend_string *user_str;
457+
zend_long user_long;
465458
#if !defined(WINDOWS)
466459
uid_t uid;
467460
int ret;
@@ -470,24 +463,22 @@ static void php_do_chown(INTERNAL_FUNCTION_PARAMETERS, int do_lchown) /* {{{ */
470463

471464
ZEND_PARSE_PARAMETERS_START(2, 2)
472465
Z_PARAM_PATH(filename, filename_len)
473-
Z_PARAM_ZVAL(user)
466+
Z_PARAM_STR_OR_LONG(user_str, user_long)
474467
ZEND_PARSE_PARAMETERS_END();
475468

476469
wrapper = php_stream_locate_url_wrapper(filename, NULL, 0);
477470
if(wrapper != &php_plain_files_wrapper || strncasecmp("file://", filename, 7) == 0) {
478471
if(wrapper && wrapper->wops->stream_metadata) {
479472
int option;
480473
void *value;
481-
if (Z_TYPE_P(user) == IS_LONG) {
482-
option = PHP_STREAM_META_OWNER;
483-
value = &Z_LVAL_P(user);
484-
} else if (Z_TYPE_P(user) == IS_STRING) {
474+
if (user_str) {
485475
option = PHP_STREAM_META_OWNER_NAME;
486-
value = Z_STRVAL_P(user);
476+
value = user_str;
487477
} else {
488-
php_error_docref(NULL, E_WARNING, "Parameter 2 should be string or int, %s given", zend_zval_type_name(user));
489-
RETURN_FALSE;
478+
option = PHP_STREAM_META_OWNER;
479+
value = &user_long;
490480
}
481+
491482
if(wrapper->wops->stream_metadata(wrapper, filename, option, value, NULL)) {
492483
RETURN_TRUE;
493484
} else {
@@ -507,16 +498,13 @@ static void php_do_chown(INTERNAL_FUNCTION_PARAMETERS, int do_lchown) /* {{{ */
507498
RETURN_FALSE;
508499
#else
509500

510-
if (Z_TYPE_P(user) == IS_LONG) {
511-
uid = (uid_t)Z_LVAL_P(user);
512-
} else if (Z_TYPE_P(user) == IS_STRING) {
513-
if(php_get_uid_by_name(Z_STRVAL_P(user), &uid) != SUCCESS) {
514-
php_error_docref(NULL, E_WARNING, "Unable to find uid for %s", Z_STRVAL_P(user));
501+
if (user_str) {
502+
if (php_get_uid_by_name(ZSTR_VAL(user_str), &uid) != SUCCESS) {
503+
php_error_docref(NULL, E_WARNING, "Unable to find uid for %s", ZSTR_VAL(user_str));
515504
RETURN_FALSE;
516505
}
517506
} else {
518-
php_error_docref(NULL, E_WARNING, "Parameter 2 should be string or int, %s given", zend_zval_type_name(user));
519-
RETURN_FALSE;
507+
uid = (uid_t) user_long;
520508
}
521509

522510
/* Check the basedir */
@@ -552,12 +540,8 @@ PHP_FUNCTION(chown)
552540
#if HAVE_LCHOWN
553541
PHP_FUNCTION(lchown)
554542
{
555-
# if !defined(WINDOWS)
556543
RETVAL_TRUE;
557544
php_do_chown(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
558-
# else
559-
RETURN_FALSE;
560-
# endif
561545
}
562546
#endif
563547
/* }}} */

ext/standard/tests/file/chgrp.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ try {
1414
}
1515
?>
1616
--EXPECT--
17-
chgrp(): Argument #2 ($group) must be of type string|int, null given
17+
Warning: chgrp(): No such file or directory in %s on line %d

ext/standard/tests/file/chown.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ chown("sjhgfskhagkfdgskjfhgskfsdgfkdsajf", NULL);
1111
echo "ALIVE\n";
1212
?>
1313
--EXPECTF--
14-
Warning: chown(): Parameter 2 should be string or int, null given in %schown.php on line %d
14+
Warning: chown(): No such file or directory in %s on %d
1515
ALIVE

0 commit comments

Comments
 (0)