Skip to content

Commit a981ad7

Browse files
committed
Merge branch 'PHP-8.2'
* PHP-8.2: Add support for generating namespaced constant
2 parents 8995f60 + 7fccdf7 commit a981ad7

File tree

8 files changed

+86
-47
lines changed

8 files changed

+86
-47
lines changed

build/gen_stub.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -931,8 +931,11 @@ public function isUnknown(): bool
931931
class ConstName extends AbstractConstName {
932932
public string $const;
933933

934-
public function __construct(string $const)
934+
public function __construct(?Name $namespace, string $const)
935935
{
936+
if ($namespace && ($namespace = $namespace->slice(0, -1))) {
937+
$const = $namespace->toString() . '\\' . $const;
938+
}
936939
$this->const = $const;
937940
}
938941

@@ -941,6 +944,15 @@ public function isClassConst(): bool
941944
return false;
942945
}
943946

947+
public function isUnknown(): bool
948+
{
949+
$name = $this->__toString();
950+
if (($pos = strrpos($name, '\\')) !== false) {
951+
$name = substr($name, $pos + 1);
952+
}
953+
return strtolower($name) === "unknown";
954+
}
955+
944956
public function __toString(): string
945957
{
946958
return $this->const;
@@ -1600,7 +1612,7 @@ public function enterNode(Node $expr)
16001612
if ($expr instanceof Expr\ClassConstFetch) {
16011613
$originatingConstName = new ClassConstName($expr->class, $expr->name->toString());
16021614
} else {
1603-
$originatingConstName = new ConstName($expr->name->toString());
1615+
$originatingConstName = new ConstName($expr->name->getAttribute('namespacedName'), $expr->name->toString());
16041616
}
16051617

16061618
if ($originatingConstName->isUnknown()) {
@@ -3677,7 +3689,7 @@ function handleStatements(FileInfo $fileInfo, array $stmts, PrettyPrinterAbstrac
36773689
foreach ($stmt->consts as $const) {
36783690
$fileInfo->constInfos[] = parseConstLike(
36793691
$prettyPrinter,
3680-
new ConstName($const->name->toString()),
3692+
new ConstName($const->namespacedName, $const->name->toString()),
36813693
$const,
36823694
0,
36833695
$stmt->getDocComment(),

ext/ftp/ftp.stub.php

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

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

5-
namespace FTP {
5+
namespace {
66
/**
77
* @var int
88
* @cvalue FTPTYPE_ASCII
@@ -59,16 +59,6 @@
5959
*/
6060
const FTP_MOREDATA = UNKNOWN;
6161

62-
/**
63-
* @strict-properties
64-
* @not-serializable
65-
*/
66-
final class Connection
67-
{
68-
}
69-
}
70-
71-
namespace {
7262
function ftp_connect(string $hostname, int $port = 21, int $timeout = 90): FTP\Connection|false {}
7363

7464
#ifdef HAVE_FTP_SSL
@@ -145,3 +135,13 @@ function ftp_quit(FTP\Connection $ftp): bool {}
145135
function ftp_set_option(FTP\Connection $ftp, int $option, $value): bool {}
146136
function ftp_get_option(FTP\Connection $ftp, int $option): int|bool {}
147137
}
138+
139+
namespace FTP {
140+
/**
141+
* @strict-properties
142+
* @not-serializable
143+
*/
144+
final class Connection
145+
{
146+
}
147+
}

ext/ftp/ftp_arginfo.h

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

ext/pgsql/pgsql.stub.php

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

5-
namespace PgSql {
5+
namespace {
66
/* libpq version */
77

88
/**
@@ -413,34 +413,6 @@
413413
*/
414414
const PGSQL_DML_STRING = UNKNOWN;
415415

416-
/**
417-
* @strict-properties
418-
* @not-serializable
419-
*/
420-
final class Connection
421-
{
422-
}
423-
424-
/**
425-
* @strict-properties
426-
* @not-serializable
427-
*/
428-
final class Result
429-
{
430-
}
431-
432-
/**
433-
* @strict-properties
434-
* @not-serializable
435-
*/
436-
final class Lob
437-
{
438-
}
439-
440-
}
441-
442-
namespace {
443-
444416
function pg_connect(string $connection_string, int $flags = 0): PgSql\Connection|false {}
445417

446418
function pg_pconnect(string $connection_string, int $flags = 0): PgSql\Connection|false {}
@@ -923,3 +895,30 @@ function pg_delete(PgSql\Connection $connection, string $table_name, array $cond
923895
*/
924896
function pg_select(PgSql\Connection $connection, string $table_name, array $conditions, int $flags = PGSQL_DML_EXEC, int $mode = PGSQL_ASSOC): array|string|false {}
925897
}
898+
899+
namespace PgSql {
900+
/**
901+
* @strict-properties
902+
* @not-serializable
903+
*/
904+
final class Connection
905+
{
906+
}
907+
908+
/**
909+
* @strict-properties
910+
* @not-serializable
911+
*/
912+
final class Result
913+
{
914+
}
915+
916+
/**
917+
* @strict-properties
918+
* @not-serializable
919+
*/
920+
final class Lob
921+
{
922+
}
923+
924+
}

ext/pgsql/pgsql_arginfo.h

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

ext/zend_test/test.stub.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66
* @undocumentable
77
*/
88
namespace {
9+
require "Zend/zend_attributes.stub.php";
10+
911
/**
1012
* @var int
1113
* @deprecated
1214
*/
1315
const ZEND_TEST_DEPRECATED = 42;
1416

15-
require "Zend/zend_attributes.stub.php";
17+
/** @var string */
18+
const ZEND_CONSTANT_A = "global";
1619

1720
interface _ZendTestInterface
1821
{
@@ -199,6 +202,9 @@ public function method(): ?UnlikelyCompileError {}
199202

200203
namespace ZendTestNS2 {
201204

205+
/** @var string */
206+
const ZEND_CONSTANT_A = "namespaced";
207+
202208
class Foo {
203209
public ZendSubNS\Foo $foo;
204210

@@ -222,6 +228,9 @@ function namespaced_deprecated_aliased_func(): void {}
222228

223229
namespace ZendTestNS2\ZendSubNS {
224230

231+
/** @var string */
232+
const ZEND_CONSTANT_A = \ZendTestNS2\ZEND_CONSTANT_A;
233+
225234
class Foo {
226235
public function method(): void {}
227236
}

ext/zend_test/test_arginfo.h

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
gen_stub.php: constants
3+
--EXTENSIONS--
4+
zend_test
5+
--FILE--
6+
<?php
7+
8+
var_dump(ZEND_CONSTANT_A);
9+
var_dump(ZendTestNS2\ZEND_CONSTANT_A);
10+
var_dump(ZendTestNS2\ZendSubNS\ZEND_CONSTANT_A);
11+
12+
?>
13+
--EXPECT--
14+
string(6) "global"
15+
string(10) "namespaced"
16+
string(10) "namespaced"

0 commit comments

Comments
 (0)