mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Merge branch 'PHP-8.2'
* PHP-8.2: Add support for generating namespaced constant
This commit is contained in:
commit
a981ad7ad2
8 changed files with 86 additions and 47 deletions
|
@ -931,8 +931,11 @@ abstract class AbstractConstName implements ConstOrClassConstName
|
|||
class ConstName extends AbstractConstName {
|
||||
public string $const;
|
||||
|
||||
public function __construct(string $const)
|
||||
public function __construct(?Name $namespace, string $const)
|
||||
{
|
||||
if ($namespace && ($namespace = $namespace->slice(0, -1))) {
|
||||
$const = $namespace->toString() . '\\' . $const;
|
||||
}
|
||||
$this->const = $const;
|
||||
}
|
||||
|
||||
|
@ -941,6 +944,15 @@ class ConstName extends AbstractConstName {
|
|||
return false;
|
||||
}
|
||||
|
||||
public function isUnknown(): bool
|
||||
{
|
||||
$name = $this->__toString();
|
||||
if (($pos = strrpos($name, '\\')) !== false) {
|
||||
$name = substr($name, $pos + 1);
|
||||
}
|
||||
return strtolower($name) === "unknown";
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->const;
|
||||
|
@ -1600,7 +1612,7 @@ class EvaluatedValue
|
|||
if ($expr instanceof Expr\ClassConstFetch) {
|
||||
$originatingConstName = new ClassConstName($expr->class, $expr->name->toString());
|
||||
} else {
|
||||
$originatingConstName = new ConstName($expr->name->toString());
|
||||
$originatingConstName = new ConstName($expr->name->getAttribute('namespacedName'), $expr->name->toString());
|
||||
}
|
||||
|
||||
if ($originatingConstName->isUnknown()) {
|
||||
|
@ -3677,7 +3689,7 @@ function handleStatements(FileInfo $fileInfo, array $stmts, PrettyPrinterAbstrac
|
|||
foreach ($stmt->consts as $const) {
|
||||
$fileInfo->constInfos[] = parseConstLike(
|
||||
$prettyPrinter,
|
||||
new ConstName($const->name->toString()),
|
||||
new ConstName($const->namespacedName, $const->name->toString()),
|
||||
$const,
|
||||
0,
|
||||
$stmt->getDocComment(),
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/** @generate-class-entries */
|
||||
|
||||
namespace FTP {
|
||||
namespace {
|
||||
/**
|
||||
* @var int
|
||||
* @cvalue FTPTYPE_ASCII
|
||||
|
@ -59,16 +59,6 @@ namespace FTP {
|
|||
*/
|
||||
const FTP_MOREDATA = UNKNOWN;
|
||||
|
||||
/**
|
||||
* @strict-properties
|
||||
* @not-serializable
|
||||
*/
|
||||
final class Connection
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
function ftp_connect(string $hostname, int $port = 21, int $timeout = 90): FTP\Connection|false {}
|
||||
|
||||
#ifdef HAVE_FTP_SSL
|
||||
|
@ -145,3 +135,13 @@ namespace {
|
|||
function ftp_set_option(FTP\Connection $ftp, int $option, $value): bool {}
|
||||
function ftp_get_option(FTP\Connection $ftp, int $option): int|bool {}
|
||||
}
|
||||
|
||||
namespace FTP {
|
||||
/**
|
||||
* @strict-properties
|
||||
* @not-serializable
|
||||
*/
|
||||
final class Connection
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
2
ext/ftp/ftp_arginfo.h
generated
2
ext/ftp/ftp_arginfo.h
generated
|
@ -1,5 +1,5 @@
|
|||
/* This is a generated file, edit the .stub.php file instead.
|
||||
* Stub hash: 1f66f9b5745bebb0280464b3c1a7f8413c0c6ebc */
|
||||
* Stub hash: ba6c48ea91e85eefb9238ad6cd036fc9b63a75a8 */
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_ftp_connect, 0, 1, FTP\\Connection, MAY_BE_FALSE)
|
||||
ZEND_ARG_TYPE_INFO(0, hostname, IS_STRING, 0)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/** @generate-class-entries */
|
||||
|
||||
namespace PgSql {
|
||||
namespace {
|
||||
/* libpq version */
|
||||
|
||||
/**
|
||||
|
@ -413,34 +413,6 @@ namespace PgSql {
|
|||
*/
|
||||
const PGSQL_DML_STRING = UNKNOWN;
|
||||
|
||||
/**
|
||||
* @strict-properties
|
||||
* @not-serializable
|
||||
*/
|
||||
final class Connection
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @strict-properties
|
||||
* @not-serializable
|
||||
*/
|
||||
final class Result
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @strict-properties
|
||||
* @not-serializable
|
||||
*/
|
||||
final class Lob
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
function pg_connect(string $connection_string, int $flags = 0): PgSql\Connection|false {}
|
||||
|
||||
function pg_pconnect(string $connection_string, int $flags = 0): PgSql\Connection|false {}
|
||||
|
@ -923,3 +895,30 @@ namespace {
|
|||
*/
|
||||
function pg_select(PgSql\Connection $connection, string $table_name, array $conditions, int $flags = PGSQL_DML_EXEC, int $mode = PGSQL_ASSOC): array|string|false {}
|
||||
}
|
||||
|
||||
namespace PgSql {
|
||||
/**
|
||||
* @strict-properties
|
||||
* @not-serializable
|
||||
*/
|
||||
final class Connection
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @strict-properties
|
||||
* @not-serializable
|
||||
*/
|
||||
final class Result
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @strict-properties
|
||||
* @not-serializable
|
||||
*/
|
||||
final class Lob
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
|
2
ext/pgsql/pgsql_arginfo.h
generated
2
ext/pgsql/pgsql_arginfo.h
generated
|
@ -1,5 +1,5 @@
|
|||
/* This is a generated file, edit the .stub.php file instead.
|
||||
* Stub hash: 16b910c38da087e1b4b55e38031b593334c698ec */
|
||||
* Stub hash: 52d055086569456122f9d9a1264f7a3667127ea7 */
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_pg_connect, 0, 1, PgSql\\Connection, MAY_BE_FALSE)
|
||||
ZEND_ARG_TYPE_INFO(0, connection_string, IS_STRING, 0)
|
||||
|
|
|
@ -6,13 +6,16 @@
|
|||
* @undocumentable
|
||||
*/
|
||||
namespace {
|
||||
require "Zend/zend_attributes.stub.php";
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* @deprecated
|
||||
*/
|
||||
const ZEND_TEST_DEPRECATED = 42;
|
||||
|
||||
require "Zend/zend_attributes.stub.php";
|
||||
/** @var string */
|
||||
const ZEND_CONSTANT_A = "global";
|
||||
|
||||
interface _ZendTestInterface
|
||||
{
|
||||
|
@ -199,6 +202,9 @@ namespace ZendTestNS {
|
|||
|
||||
namespace ZendTestNS2 {
|
||||
|
||||
/** @var string */
|
||||
const ZEND_CONSTANT_A = "namespaced";
|
||||
|
||||
class Foo {
|
||||
public ZendSubNS\Foo $foo;
|
||||
|
||||
|
@ -222,6 +228,9 @@ namespace ZendTestNS2 {
|
|||
|
||||
namespace ZendTestNS2\ZendSubNS {
|
||||
|
||||
/** @var string */
|
||||
const ZEND_CONSTANT_A = \ZendTestNS2\ZEND_CONSTANT_A;
|
||||
|
||||
class Foo {
|
||||
public function method(): void {}
|
||||
}
|
||||
|
|
5
ext/zend_test/test_arginfo.h
generated
5
ext/zend_test/test_arginfo.h
generated
|
@ -1,5 +1,5 @@
|
|||
/* This is a generated file, edit the .stub.php file instead.
|
||||
* Stub hash: 80543c60da9d2732e677375e49afc21c91bf594b */
|
||||
* Stub hash: 8a5914eead09c2a85fd7d53d63c9597dfb3d0c30 */
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_test_array_return, 0, 0, IS_ARRAY, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
@ -379,6 +379,9 @@ static const zend_function_entry class_ZendTestNS2_ZendSubNS_Foo_methods[] = {
|
|||
static void register_test_symbols(int module_number)
|
||||
{
|
||||
REGISTER_LONG_CONSTANT("ZEND_TEST_DEPRECATED", 42, CONST_PERSISTENT | CONST_DEPRECATED);
|
||||
REGISTER_STRING_CONSTANT("ZEND_CONSTANT_A", "global", CONST_PERSISTENT);
|
||||
REGISTER_STRING_CONSTANT("ZendTestNS2\\ZEND_CONSTANT_A", "namespaced", CONST_PERSISTENT);
|
||||
REGISTER_STRING_CONSTANT("ZendTestNS2\\ZendSubNS\\ZEND_CONSTANT_A", "namespaced", CONST_PERSISTENT);
|
||||
|
||||
|
||||
zend_string *attribute_name_ZendTestParameterAttribute_zend_test_parameter_with_attribute_arg0 = zend_string_init_interned("ZendTestParameterAttribute", sizeof("ZendTestParameterAttribute") - 1, 1);
|
||||
|
|
16
ext/zend_test/tests/gen_stub_test_02.phpt
Normal file
16
ext/zend_test/tests/gen_stub_test_02.phpt
Normal file
|
@ -0,0 +1,16 @@
|
|||
--TEST--
|
||||
gen_stub.php: constants
|
||||
--EXTENSIONS--
|
||||
zend_test
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
var_dump(ZEND_CONSTANT_A);
|
||||
var_dump(ZendTestNS2\ZEND_CONSTANT_A);
|
||||
var_dump(ZendTestNS2\ZendSubNS\ZEND_CONSTANT_A);
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
string(6) "global"
|
||||
string(10) "namespaced"
|
||||
string(10) "namespaced"
|
Loading…
Add table
Add a link
Reference in a new issue