Skip to content

Generate class entries from stubs for ldap, libxml, mbstring and mysqli #6684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions build/gen_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -1117,12 +1117,13 @@ private function initializeValue(string $type, $value, bool $isTyped): string
if (empty($value)) {
$code .= "\tZVAL_EMPTY_STRING(&$zvalName);\n";
} else {
$code .= "\tZVAL_STRING(&$zvalName, \"$value\");\n";
$code .= "\tzend_string *{$zvalName}_str = zend_string_init(\"$value\", sizeof(\"$value\") - 1, 1);\n";
$code .= "\tZVAL_STR(&$zvalName, {$zvalName}_str);\n";
}
break;

case "array":
if (empty($value)) {
if ($value === "") {
$code .= "\tZVAL_EMPTY_ARRAY(&$zvalName);\n";
} else {
throw new Exception("Unimplemented property default value");
Expand Down
2 changes: 1 addition & 1 deletion ext/ldap/ldap.stub.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/** @generate-function-entries */
/** @generate-class-entries */

#ifdef HAVE_ORALDAP
/** @return resource|false */
Expand Down
3 changes: 2 additions & 1 deletion ext/ldap/ldap_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 9d6315aeee2e3a1be51c05b65a960ed433bbe4ec */
* Stub hash: 056fa51afdd7d40f9866ebd67837f5ddfa2c6236 */

#if defined(HAVE_ORALDAP)
ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_connect, 0, 0, 0)
Expand Down Expand Up @@ -538,3 +538,4 @@ static const zend_function_entry ext_functions[] = {
#endif
ZEND_FE_END
};

1 change: 1 addition & 0 deletions ext/libxml/libxml.stub.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

/** @generate-class-entries */

class LibXMLError
{
public int $level;
Expand Down
2 changes: 1 addition & 1 deletion ext/libxml/libxml_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: f07180b33955d802c40f3f52f6199605508df87b */
* Stub hash: 252fdc1cd83d2d3322cc040baf2bf3c7fde29254 */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_libxml_set_streams_context, 0, 1, IS_VOID, 0)
ZEND_ARG_INFO(0, context)
Expand Down
2 changes: 1 addition & 1 deletion ext/mbstring/mbstring.stub.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/** @generate-function-entries */
/** @generate-class-entries */

function mb_language(?string $language = null): string|bool {}

Expand Down
3 changes: 2 additions & 1 deletion ext/mbstring/mbstring_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 51f0769423c046d612adf81091192165ad265456 */
* Stub hash: eef196b29323ceb0a5d67703e62b11d0004c615b */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_language, 0, 0, MAY_BE_STRING|MAY_BE_BOOL)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, language, IS_STRING, 1, "null")
Expand Down Expand Up @@ -490,3 +490,4 @@ static const zend_function_entry ext_functions[] = {
#endif
ZEND_FE_END
};

88 changes: 19 additions & 69 deletions ext/mysqli/mysqli.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,6 @@ static PHP_GINIT_FUNCTION(mysqli)
/* {{{ PHP_MINIT_FUNCTION */
PHP_MINIT_FUNCTION(mysqli)
{
zend_class_entry *ce,cex;

REGISTER_INI_ENTRIES();
#ifndef MYSQLI_USE_MYSQLND
if (mysql_server_init(0, NULL, NULL)) {
Expand Down Expand Up @@ -564,86 +562,38 @@ PHP_MINIT_FUNCTION(mysqli)
le_pmysqli = zend_register_list_destructors_ex(NULL, php_mysqli_dtor,
"MySqli persistent connection", module_number);

INIT_CLASS_ENTRY(cex, "mysqli_sql_exception", class_mysqli_sql_exception_methods);
mysqli_exception_class_entry = zend_register_internal_class_ex(&cex, spl_ce_RuntimeException);
mysqli_exception_class_entry->ce_flags |= ZEND_ACC_FINAL;
zend_declare_property_long(mysqli_exception_class_entry, "code", sizeof("code")-1, 0, ZEND_ACC_PROTECTED);
zend_declare_property_string(mysqli_exception_class_entry, "sqlstate", sizeof("sqlstate")-1, "00000", ZEND_ACC_PROTECTED);
mysqli_exception_class_entry = register_class_mysqli_sql_exception(spl_ce_RuntimeException);

REGISTER_MYSQLI_CLASS_ENTRY("mysqli_driver", mysqli_driver_class_entry, class_mysqli_driver_methods);
ce = mysqli_driver_class_entry;
mysqli_driver_class_entry = register_class_mysqli_driver();
mysqli_driver_class_entry->create_object = mysqli_objects_new;
zend_hash_init(&mysqli_driver_properties, 0, NULL, free_prop_handler, 1);
MYSQLI_ADD_PROPERTIES(&mysqli_driver_properties, mysqli_driver_property_entries);
zend_declare_property_null(ce, "client_info", sizeof("client_info") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "client_version", sizeof("client_version") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "driver_version", sizeof("driver_version") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "reconnect", sizeof("reconnect") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "report_mode", sizeof("report_mode") - 1, ZEND_ACC_PUBLIC);
ce->ce_flags |= ZEND_ACC_FINAL;
zend_hash_add_ptr(&classes, ce->name, &mysqli_driver_properties);

REGISTER_MYSQLI_CLASS_ENTRY("mysqli", mysqli_link_class_entry, class_mysqli_methods);
ce = mysqli_link_class_entry;
zend_hash_add_ptr(&classes, mysqli_driver_class_entry->name, &mysqli_driver_properties);

mysqli_link_class_entry = register_class_mysqli();
mysqli_link_class_entry->create_object = mysqli_objects_new;
zend_hash_init(&mysqli_link_properties, 0, NULL, free_prop_handler, 1);
MYSQLI_ADD_PROPERTIES(&mysqli_link_properties, mysqli_link_property_entries);
zend_declare_property_null(ce, "affected_rows", sizeof("affected_rows") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "client_info", sizeof("client_info") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "client_version", sizeof("client_version") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "connect_errno", sizeof("connect_errno") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "connect_error", sizeof("connect_error") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "errno", sizeof("errno") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "error", sizeof("error") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "error_list", sizeof("error_list") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "field_count", sizeof("field_count") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "host_info", sizeof("host_info") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "info", sizeof("info") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "insert_id", sizeof("insert_id") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "server_info", sizeof("server_info") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "server_version", sizeof("server_version") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "sqlstate", sizeof("sqlstate") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "protocol_version", sizeof("protocol_version") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "thread_id", sizeof("thread_id") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "warning_count", sizeof("warning_count") - 1, ZEND_ACC_PUBLIC);
zend_hash_add_ptr(&classes, ce->name, &mysqli_link_properties);

REGISTER_MYSQLI_CLASS_ENTRY("mysqli_warning", mysqli_warning_class_entry, class_mysqli_warning_methods);
ce = mysqli_warning_class_entry;
ce->ce_flags |= ZEND_ACC_FINAL;
zend_hash_add_ptr(&classes, mysqli_link_class_entry->name, &mysqli_link_properties);

mysqli_warning_class_entry = register_class_mysqli_warning();
mysqli_warning_class_entry->create_object = mysqli_objects_new;
zend_hash_init(&mysqli_warning_properties, 0, NULL, free_prop_handler, 1);
MYSQLI_ADD_PROPERTIES(&mysqli_warning_properties, mysqli_warning_property_entries);
zend_declare_property_null(ce, "message", sizeof("message") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "sqlstate", sizeof("sqlstate") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "errno", sizeof("errno") - 1, ZEND_ACC_PUBLIC);
zend_hash_add_ptr(&classes, ce->name, &mysqli_warning_properties);
zend_hash_add_ptr(&classes, mysqli_warning_class_entry->name, &mysqli_warning_properties);

REGISTER_MYSQLI_CLASS_ENTRY("mysqli_result", mysqli_result_class_entry, class_mysqli_result_methods);
ce = mysqli_result_class_entry;
mysqli_result_class_entry = register_class_mysqli_result(zend_ce_aggregate);
mysqli_result_class_entry->create_object = mysqli_objects_new;
mysqli_result_class_entry->get_iterator = php_mysqli_result_get_iterator;
zend_hash_init(&mysqli_result_properties, 0, NULL, free_prop_handler, 1);
MYSQLI_ADD_PROPERTIES(&mysqli_result_properties, mysqli_result_property_entries);
zend_declare_property_null(ce, "current_field", sizeof("current_field") - 1,ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "field_count", sizeof("field_count") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "lengths", sizeof("lengths") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "num_rows", sizeof("num_rows") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "type", sizeof("type") - 1, ZEND_ACC_PUBLIC);
mysqli_result_class_entry->get_iterator = php_mysqli_result_get_iterator;
zend_class_implements(mysqli_result_class_entry, 1, zend_ce_aggregate);
zend_hash_add_ptr(&classes, ce->name, &mysqli_result_properties);
zend_hash_add_ptr(&classes, mysqli_result_class_entry->name, &mysqli_result_properties);

REGISTER_MYSQLI_CLASS_ENTRY("mysqli_stmt", mysqli_stmt_class_entry, class_mysqli_stmt_methods);
ce = mysqli_stmt_class_entry;
mysqli_stmt_class_entry = register_class_mysqli_stmt();
mysqli_stmt_class_entry->create_object = mysqli_objects_new;
zend_hash_init(&mysqli_stmt_properties, 0, NULL, free_prop_handler, 1);
MYSQLI_ADD_PROPERTIES(&mysqli_stmt_properties, mysqli_stmt_property_entries);
zend_declare_property_null(ce, "affected_rows", sizeof("affected_rows") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "insert_id", sizeof("insert_id") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "num_rows", sizeof("num_rows") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "param_count", sizeof("param_count") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "field_count", sizeof("field_count") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "errno", sizeof("errno") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "error", sizeof("error") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "error_list", sizeof("error_list") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "sqlstate", sizeof("sqlstate") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "id", sizeof("id") - 1, ZEND_ACC_PUBLIC);
zend_hash_add_ptr(&classes, ce->name, &mysqli_stmt_properties);
zend_hash_add_ptr(&classes, mysqli_stmt_class_entry->name, &mysqli_stmt_properties);

/* mysqli_options */
REGISTER_LONG_CONSTANT("MYSQLI_READ_DEFAULT_GROUP", MYSQL_READ_DEFAULT_GROUP, CONST_CS | CONST_PERSISTENT);
Expand Down
126 changes: 125 additions & 1 deletion ext/mysqli/mysqli.stub.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,81 @@
<?php

/** @generate-function-entries */
/** @generate-class-entries */

final class mysqli_driver
{
/** @var string|null */
public $client_info;

/** @var int|null */
public $client_version;

/** @var int|null */
public $driver_version;

/** @var bool|null */
public $reconnect;

/** @var int|null */
public $report_mode;
}

class mysqli
{
/** @var int|string|null */
public $affected_rows;

/** @var string|null */
public $client_info;

/** @var string|null */
public $client_version;

/** @var int|null */
public $connect_errno;

/** @var string|null */
public $connect_error;

/** @var int|string|null */
public $errno;

/** @var string|null */
public $error;

/** @var array|null */
public $error_list;

/** @var int|null */
public $field_count;

/** @var string|null */
public $host_info;

/** @var string|null */
public $info;

/** @var int|string|null */
public $insert_id;

/** @var string|null */
public $server_info;

/** @var int|string|null */
public $server_version;

/** @var string|null */
public $sqlstate;

/** @var int|string|null */
public $protocol_version;

/** @var int|string|null */
public $thread_id;

/** @var int|string|null */
public $warning_count;

public function __construct(
?string $hostname = null,
?string $username = null,
Expand Down Expand Up @@ -302,6 +370,21 @@ public function refresh(int $flags) {}

class mysqli_result implements IteratorAggregate
{
/** @var int|string|null */
public $current_field;

/** @var int|string|null */
public $field_count;

/** @var array|null */
public $lengths;

/** @var int|string|null */
public $num_rows;

/** @var int|null */
public $type;

public function __construct(mysqli $mysql, int $result_mode = MYSQLI_STORE_RESULT) {}

/**
Expand Down Expand Up @@ -387,6 +470,36 @@ public function getIterator(): Iterator;

class mysqli_stmt
{
/** @var int|string|null */
public $affected_rows;

/** @var int|string|null */
public $insert_id;

/** @var int|string|null */
public $num_rows;

/** @var int|string|null */
public $param_count;

/** @var int|string|null */
public $field_count;

/** @var int|string|null */
public $errno;

/** @var string|null */
public $error;

/** @var array|null */
public $error_list;

/** @var string|null */
public $sqlstate;

/** @var int|null */
public $id;

public function __construct(mysqli $mysql, ?string $query = null) {}

/**
Expand Down Expand Up @@ -510,13 +623,24 @@ public function get_result() {}

final class mysqli_warning
{
/** @var string|null */
public $message;

/** @var string|null */
public $sqlstate;

/** @var int|null */
public $errno;

private function __construct() {}

public function next(): bool {}
}

final class mysqli_sql_exception extends RuntimeException
{
/** @var string */
protected $sqlstate = "00000";
}

function mysqli_affected_rows(mysqli $mysql): int|string {}
Expand Down
Loading