Skip to content

Commit 340b94e

Browse files
committed
Merge branch 'PHP-8.2'
* PHP-8.2: Declare ext/standard constants in stubs - part 7 (#9505)
2 parents ec6893e + 3227d04 commit 340b94e

File tree

5 files changed

+126
-51
lines changed

5 files changed

+126
-51
lines changed

ext/standard/basic_functions.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ PHP_MINIT_FUNCTION(basic) /* {{{ */
304304

305305
register_phpinfo_constants(INIT_FUNC_ARGS_PASSTHRU);
306306
register_html_constants(INIT_FUNC_ARGS_PASSTHRU);
307-
register_string_constants(INIT_FUNC_ARGS_PASSTHRU);
308307

309308
BASIC_MINIT_SUBMODULE(var)
310309
BASIC_MINIT_SUBMODULE(file)

ext/standard/basic_functions.stub.php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,93 @@
740740
const LOG_PERROR = UNKNOWN;
741741
#endif
742742

743+
/* string.c */
744+
745+
/**
746+
* @var int
747+
* @cvalue PHP_STR_PAD_LEFT
748+
*/
749+
const STR_PAD_LEFT = UNKNOWN;
750+
/**
751+
* @var int
752+
* @cvalue PHP_STR_PAD_RIGHT
753+
*/
754+
const STR_PAD_RIGHT = UNKNOWN;
755+
/**
756+
* @var int
757+
* @cvalue PHP_STR_PAD_BOTH
758+
*/
759+
const STR_PAD_BOTH = UNKNOWN;
760+
/**
761+
* @var int
762+
* @cvalue PHP_PATHINFO_DIRNAME
763+
*/
764+
const PATHINFO_DIRNAME = UNKNOWN;
765+
/**
766+
* @var int
767+
* @cvalue PHP_PATHINFO_BASENAME
768+
*/
769+
const PATHINFO_BASENAME = UNKNOWN;
770+
/**
771+
* @var int
772+
* @cvalue PHP_PATHINFO_EXTENSION
773+
*/
774+
const PATHINFO_EXTENSION = UNKNOWN;
775+
/**
776+
* @var int
777+
* @cvalue PHP_PATHINFO_FILENAME
778+
*/
779+
const PATHINFO_FILENAME = UNKNOWN;
780+
/**
781+
* @var int
782+
* @cvalue PHP_PATHINFO_ALL
783+
*/
784+
const PATHINFO_ALL = UNKNOWN;
785+
786+
/**
787+
* If last members of struct lconv equal CHAR_MAX, no grouping is done
788+
* @var int
789+
* @cvalue CHAR_MAX
790+
*/
791+
const CHAR_MAX = UNKNOWN;
792+
/**
793+
* @var int
794+
* @cvalue LC_CTYPE
795+
*/
796+
const LC_CTYPE = UNKNOWN;
797+
/**
798+
* @var int
799+
* @cvalue LC_NUMERIC
800+
*/
801+
const LC_NUMERIC = UNKNOWN;
802+
/**
803+
* @var int
804+
* @cvalue LC_TIME
805+
*/
806+
const LC_TIME = UNKNOWN;
807+
/**
808+
* @var int
809+
* @cvalue LC_COLLATE
810+
*/
811+
const LC_COLLATE = UNKNOWN;
812+
/**
813+
* @var int
814+
* @cvalue LC_MONETARY
815+
*/
816+
const LC_MONETARY = UNKNOWN;
817+
/**
818+
* @var int
819+
* @cvalue LC_ALL
820+
*/
821+
const LC_ALL = UNKNOWN;
822+
#ifdef LC_MESSAGES
823+
/**
824+
* @var int
825+
* @cvalue LC_MESSAGES
826+
*/
827+
const LC_MESSAGES = UNKNOWN;
828+
#endif
829+
743830
/** @undocumentable */
744831
#[AllowDynamicProperties]
745832
final class __PHP_Incomplete_Class

ext/standard/basic_functions_arginfo.h

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/standard/php_string.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ PHPAPI bool php_binary_string_shuffle(const php_random_algo *algo, php_random_st
7878
# define php_mb_reset() php_ignore_value(mblen(NULL, 0))
7979
#endif
8080

81-
void register_string_constants(INIT_FUNC_ARGS);
81+
#define PHP_STR_PAD_LEFT 0
82+
#define PHP_STR_PAD_RIGHT 1
83+
#define PHP_STR_PAD_BOTH 2
84+
#define PHP_PATHINFO_DIRNAME 1
85+
#define PHP_PATHINFO_BASENAME 2
86+
#define PHP_PATHINFO_EXTENSION 4
87+
#define PHP_PATHINFO_FILENAME 8
88+
#define PHP_PATHINFO_ALL (PHP_PATHINFO_DIRNAME | PHP_PATHINFO_BASENAME | PHP_PATHINFO_EXTENSION | PHP_PATHINFO_FILENAME)
89+
90+
#define PHP_STR_STRSPN 0
91+
#define PHP_STR_STRCSPN 1
8292

8393
#endif /* PHP_STRING_H */

ext/standard/string.c

Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -50,45 +50,6 @@
5050
#include <emmintrin.h>
5151
#endif
5252

53-
#define STR_PAD_LEFT 0
54-
#define STR_PAD_RIGHT 1
55-
#define STR_PAD_BOTH 2
56-
#define PHP_PATHINFO_DIRNAME 1
57-
#define PHP_PATHINFO_BASENAME 2
58-
#define PHP_PATHINFO_EXTENSION 4
59-
#define PHP_PATHINFO_FILENAME 8
60-
#define PHP_PATHINFO_ALL (PHP_PATHINFO_DIRNAME | PHP_PATHINFO_BASENAME | PHP_PATHINFO_EXTENSION | PHP_PATHINFO_FILENAME)
61-
62-
#define STR_STRSPN 0
63-
#define STR_STRCSPN 1
64-
65-
/* {{{ register_string_constants */
66-
void register_string_constants(INIT_FUNC_ARGS)
67-
{
68-
REGISTER_LONG_CONSTANT("STR_PAD_LEFT", STR_PAD_LEFT, CONST_CS | CONST_PERSISTENT);
69-
REGISTER_LONG_CONSTANT("STR_PAD_RIGHT", STR_PAD_RIGHT, CONST_CS | CONST_PERSISTENT);
70-
REGISTER_LONG_CONSTANT("STR_PAD_BOTH", STR_PAD_BOTH, CONST_CS | CONST_PERSISTENT);
71-
REGISTER_LONG_CONSTANT("PATHINFO_DIRNAME", PHP_PATHINFO_DIRNAME, CONST_CS | CONST_PERSISTENT);
72-
REGISTER_LONG_CONSTANT("PATHINFO_BASENAME", PHP_PATHINFO_BASENAME, CONST_CS | CONST_PERSISTENT);
73-
REGISTER_LONG_CONSTANT("PATHINFO_EXTENSION", PHP_PATHINFO_EXTENSION, CONST_CS | CONST_PERSISTENT);
74-
REGISTER_LONG_CONSTANT("PATHINFO_FILENAME", PHP_PATHINFO_FILENAME, CONST_CS | CONST_PERSISTENT);
75-
REGISTER_LONG_CONSTANT("PATHINFO_ALL", PHP_PATHINFO_ALL, CONST_CS | CONST_PERSISTENT);
76-
77-
/* If last members of struct lconv equal CHAR_MAX, no grouping is done */
78-
REGISTER_LONG_CONSTANT("CHAR_MAX", CHAR_MAX, CONST_CS | CONST_PERSISTENT);
79-
REGISTER_LONG_CONSTANT("LC_CTYPE", LC_CTYPE, CONST_CS | CONST_PERSISTENT);
80-
REGISTER_LONG_CONSTANT("LC_NUMERIC", LC_NUMERIC, CONST_CS | CONST_PERSISTENT);
81-
REGISTER_LONG_CONSTANT("LC_TIME", LC_TIME, CONST_CS | CONST_PERSISTENT);
82-
REGISTER_LONG_CONSTANT("LC_COLLATE", LC_COLLATE, CONST_CS | CONST_PERSISTENT);
83-
REGISTER_LONG_CONSTANT("LC_MONETARY", LC_MONETARY, CONST_CS | CONST_PERSISTENT);
84-
REGISTER_LONG_CONSTANT("LC_ALL", LC_ALL, CONST_CS | CONST_PERSISTENT);
85-
# ifdef LC_MESSAGES
86-
REGISTER_LONG_CONSTANT("LC_MESSAGES", LC_MESSAGES, CONST_CS | CONST_PERSISTENT);
87-
# endif
88-
89-
}
90-
/* }}} */
91-
9253
/* this is read-only, so it's ok */
9354
ZEND_SET_ALIGNED(16, static const char hexconvtab[]) = "0123456789abcdef";
9455

@@ -288,13 +249,13 @@ static void php_spn_common_handler(INTERNAL_FUNCTION_PARAMETERS, int behavior) /
288249
RETURN_LONG(0);
289250
}
290251

291-
if (behavior == STR_STRSPN) {
252+
if (behavior == PHP_STR_STRSPN) {
292253
RETURN_LONG(php_strspn(ZSTR_VAL(s11) + start /*str1_start*/,
293254
ZSTR_VAL(s22) /*str2_start*/,
294255
ZSTR_VAL(s11) + start + len /*str1_end*/,
295256
ZSTR_VAL(s22) + ZSTR_LEN(s22) /*str2_end*/));
296257
} else {
297-
ZEND_ASSERT(behavior == STR_STRCSPN);
258+
ZEND_ASSERT(behavior == PHP_STR_STRCSPN);
298259
RETURN_LONG(php_strcspn(ZSTR_VAL(s11) + start /*str1_start*/,
299260
ZSTR_VAL(s22) /*str2_start*/,
300261
ZSTR_VAL(s11) + start + len /*str1_end*/,
@@ -306,14 +267,14 @@ static void php_spn_common_handler(INTERNAL_FUNCTION_PARAMETERS, int behavior) /
306267
/* {{{ Finds length of initial segment consisting entirely of characters found in mask. If start or/and length is provided works like strspn(substr($s,$start,$len),$good_chars) */
307268
PHP_FUNCTION(strspn)
308269
{
309-
php_spn_common_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, STR_STRSPN);
270+
php_spn_common_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_STR_STRSPN);
310271
}
311272
/* }}} */
312273

313274
/* {{{ Finds length of initial segment consisting entirely of characters not found in mask. If start or/and length is provide works like strcspn(substr($s,$start,$len),$bad_chars) */
314275
PHP_FUNCTION(strcspn)
315276
{
316-
php_spn_common_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, STR_STRCSPN);
277+
php_spn_common_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_STR_STRCSPN);
317278
}
318279
/* }}} */
319280

@@ -5550,7 +5511,7 @@ PHP_FUNCTION(str_pad)
55505511
size_t num_pad_chars; /* Number of padding characters (total - input size) */
55515512
char *pad_str = " "; /* Pointer to padding string */
55525513
size_t pad_str_len = 1;
5553-
zend_long pad_type_val = STR_PAD_RIGHT; /* The padding type value */
5514+
zend_long pad_type_val = PHP_STR_PAD_RIGHT; /* The padding type value */
55545515
size_t i, left_pad=0, right_pad=0;
55555516
zend_string *result = NULL; /* Resulting string */
55565517

@@ -5573,7 +5534,7 @@ PHP_FUNCTION(str_pad)
55735534
RETURN_THROWS();
55745535
}
55755536

5576-
if (pad_type_val < STR_PAD_LEFT || pad_type_val > STR_PAD_BOTH) {
5537+
if (pad_type_val < PHP_STR_PAD_LEFT || pad_type_val > PHP_STR_PAD_BOTH) {
55775538
zend_argument_value_error(4, "must be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH");
55785539
RETURN_THROWS();
55795540
}
@@ -5584,17 +5545,17 @@ PHP_FUNCTION(str_pad)
55845545

55855546
/* We need to figure out the left/right padding lengths. */
55865547
switch (pad_type_val) {
5587-
case STR_PAD_RIGHT:
5548+
case PHP_STR_PAD_RIGHT:
55885549
left_pad = 0;
55895550
right_pad = num_pad_chars;
55905551
break;
55915552

5592-
case STR_PAD_LEFT:
5553+
case PHP_STR_PAD_LEFT:
55935554
left_pad = num_pad_chars;
55945555
right_pad = 0;
55955556
break;
55965557

5597-
case STR_PAD_BOTH:
5558+
case PHP_STR_PAD_BOTH:
55985559
left_pad = num_pad_chars / 2;
55995560
right_pad = num_pad_chars - left_pad;
56005561
break;

0 commit comments

Comments
 (0)