Skip to content

Commit 5bb0315

Browse files
authored
Add the last few remaining constants to stubs (#13751)
Basically all constants are now declared via stubs. The rest of the constants are either deprecated (`SID` or `MHASH_*`) or out of interest (`__COMPILER_HALT_OFFSET__` and `PHP_CLI_PROCESS_TITLE`).
1 parent 51dafc6 commit 5bb0315

File tree

8 files changed

+51
-23
lines changed

8 files changed

+51
-23
lines changed

build/gen_stub.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2526,6 +2526,7 @@ class ConstInfo extends VariableLike
25262526
public ?string $cond;
25272527
public ?string $cValue;
25282528
public bool $isUndocumentable;
2529+
public bool $isFileCacheAllowed;
25292530

25302531
/**
25312532
* @var AttributeInfo[] $attributes
@@ -2544,7 +2545,8 @@ public function __construct(
25442545
?string $link,
25452546
?int $phpVersionIdMinimumCompatibility,
25462547
array $attributes,
2547-
?ExposedDocComment $exposedDocComment
2548+
?ExposedDocComment $exposedDocComment,
2549+
bool $isFileCacheAllowed
25482550
) {
25492551
$this->name = $name;
25502552
$this->value = $value;
@@ -2553,6 +2555,7 @@ public function __construct(
25532555
$this->cond = $cond;
25542556
$this->cValue = $cValue;
25552557
$this->isUndocumentable = $isUndocumentable;
2558+
$this->isFileCacheAllowed = $isFileCacheAllowed;
25562559
parent::__construct($flags, $type, $phpDocType, $link, $phpVersionIdMinimumCompatibility, $attributes, $exposedDocComment);
25572560
}
25582561

@@ -2698,6 +2701,9 @@ private function getGlobalConstDeclaration(EvaluatedValue $value, array $allCons
26982701
$cExpr = $value->getCExpr();
26992702

27002703
$flags = "CONST_PERSISTENT";
2704+
if (!$this->isFileCacheAllowed) {
2705+
$flags .= " | CONST_NO_FILE_CACHE";
2706+
}
27012707
if ($this->phpVersionIdMinimumCompatibility !== null && $this->phpVersionIdMinimumCompatibility < 80000) {
27022708
$flags .= " | CONST_CS";
27032709
}
@@ -2725,7 +2731,8 @@ private function getGlobalConstDeclaration(EvaluatedValue $value, array $allCons
27252731
return "\tREGISTER_STRING_CONSTANT(\"$constName\", " . ($cExpr ?: '"' . addslashes($constValue) . '"') . ", $flags);\n";
27262732
}
27272733

2728-
throw new Exception("Unimplemented constant type");}
2734+
throw new Exception("Unimplemented constant type");
2735+
}
27292736

27302737
/** @param array<string, ConstInfo> $allConstInfos */
27312738
private function getClassConstDeclaration(EvaluatedValue $value, array $allConstInfos): string
@@ -4304,6 +4311,7 @@ function parseConstLike(
43044311
$deprecated = false;
43054312
$cValue = null;
43064313
$link = null;
4314+
$isFileCacheAllowed = true;
43074315
if ($comments) {
43084316
$tags = parseDocComments($comments);
43094317
foreach ($tags as $tag) {
@@ -4317,6 +4325,8 @@ function parseConstLike(
43174325
$isUndocumentable = true;
43184326
} elseif ($tag->name === 'link') {
43194327
$link = $tag->value;
4328+
} elseif ($tag->name === 'no-file-cache') {
4329+
$isFileCacheAllowed = false;
43204330
}
43214331
}
43224332
}
@@ -4339,7 +4349,8 @@ function parseConstLike(
43394349
$link,
43404350
$phpVersionIdMinimumCompatibility,
43414351
$attributes,
4342-
createExposedDocComment($comments)
4352+
createExposedDocComment($comments),
4353+
$isFileCacheAllowed
43434354
);
43444355
}
43454356

ext/standard/dir.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ PHP_RINIT_FUNCTION(dir)
107107

108108
PHP_MINIT_FUNCTION(dir)
109109
{
110-
static char dirsep_str[2], pathsep_str[2];
110+
dirsep_str[0] = DEFAULT_SLASH;
111+
dirsep_str[1] = '\0';
112+
113+
pathsep_str[0] = ZEND_PATHS_SEPARATOR;
114+
pathsep_str[1] = '\0';
111115

112116
register_dir_symbols(module_number);
113117

@@ -117,14 +121,6 @@ PHP_MINIT_FUNCTION(dir)
117121
ts_allocate_id(&dir_globals_id, sizeof(php_dir_globals), NULL, NULL);
118122
#endif
119123

120-
dirsep_str[0] = DEFAULT_SLASH;
121-
dirsep_str[1] = '\0';
122-
REGISTER_STRING_CONSTANT("DIRECTORY_SEPARATOR", dirsep_str, CONST_PERSISTENT);
123-
124-
pathsep_str[0] = ZEND_PATHS_SEPARATOR;
125-
pathsep_str[1] = '\0';
126-
REGISTER_STRING_CONSTANT("PATH_SEPARATOR", pathsep_str, CONST_PERSISTENT);
127-
128124
return SUCCESS;
129125
}
130126
/* }}} */

ext/standard/dir.stub.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
/** @generate-class-entries */
44

5+
/**
6+
* @var string
7+
* @cvalue dirsep_str
8+
*/
9+
const DIRECTORY_SEPARATOR = UNKNOWN;
10+
/**
11+
* @var string
12+
* @cvalue pathsep_str
13+
*/
14+
const PATH_SEPARATOR = UNKNOWN;
15+
516
#ifdef HAVE_GLOB
617
#if (defined(GLOB_BRACE) && GLOB_BRACE != 0)
718
/**

ext/standard/dir_arginfo.h

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

ext/standard/php_dir_int.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,6 @@
6262

6363
#endif /* HAVE_GLOB */
6464

65+
char dirsep_str[2], pathsep_str[2];
66+
6567
#endif /* PHP_DIR_INT_H */

main/main.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,16 +2137,8 @@ zend_result php_module_startup(sapi_module_struct *sf, zend_module_entry *additi
21372137

21382138
le_index_ptr = zend_register_list_destructors_ex(NULL, NULL, "index pointer", 0);
21392139

2140-
register_main_symbols(module_number);
2141-
2142-
REGISTER_MAIN_STRINGL_CONSTANT("PHP_SAPI", sapi_module.name, strlen(sapi_module.name), CONST_PERSISTENT | CONST_NO_FILE_CACHE);
2143-
21442140
php_binary_init();
2145-
if (PG(php_binary)) {
2146-
REGISTER_MAIN_STRINGL_CONSTANT("PHP_BINARY", PG(php_binary), strlen(PG(php_binary)), CONST_PERSISTENT | CONST_NO_FILE_CACHE);
2147-
} else {
2148-
REGISTER_MAIN_STRINGL_CONSTANT("PHP_BINARY", "", 0, CONST_PERSISTENT | CONST_NO_FILE_CACHE);
2149-
}
2141+
register_main_symbols(module_number);
21502142

21512143
/* this will read in php.ini, set up the configuration parameters,
21522144
load zend extensions and register php function extensions

main/main.stub.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,3 +354,15 @@
354354
*/
355355
const ZEND_VERIFY_TYPE_INFERENCE = UNKNOWN;
356356
#endif
357+
/**
358+
* @var string
359+
* @cvalue sapi_module.name
360+
* @no-file-cache
361+
*/
362+
const PHP_SAPI = UNKNOWN;
363+
/**
364+
* @var string
365+
* @cvalue PG(php_binary) ? PG(php_binary) : ""
366+
* @no-file-cache
367+
*/
368+
const PHP_BINARY = UNKNOWN;

main/main_arginfo.h

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

0 commit comments

Comments
 (0)