Skip to content

gen_stub.php generated wrong C string #22169

@matyhtf

Description

@matyhtf

Description

The following code:

<?php
/**
 * @generate-class-entries
 */
class Test {
    protected string $x = '[{"label":"Option 1","value":"1"},{"label":"Option 2","value":"2"},{"label":"Option 3","value":"3"},{"label":"Option 4","value":"4"}]';

    protected function bar(): void {

    }
}

Resulted in this output:

php build/gen_stub.php t.stub.php
static zend_class_entry *register_class_Test(void)
{
        zend_class_entry ce, *class_entry;

        INIT_CLASS_ENTRY(ce, "Test", class_Test_methods);
        class_entry = zend_register_internal_class_with_flags(&ce, NULL, 0);

        zval property_x_default_value;
        zend_string *property_x_default_value_str = zend_string_init("[{"label":"Option 1","value":"1"},{"label":"Option 2","value":"2"},{"label":"Option 3","value":"3"},{"label":"Option 4","value":"4"}]", strlen("[{"label":"Option 1","value":"1"},{"label":"Option 2","value":"2"},{"label":"Option 3","value":"3"},{"label":"Option 4","value":"4"}]"), 1);
        ZVAL_STR(&property_x_default_value, property_x_default_value_str);
        zend_string *property_x_name = zend_string_init("x", sizeof("x") - 1, 1);
        zend_declare_typed_property(class_entry, property_x_name, &property_x_default_value, ZEND_ACC_PROTECTED, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING));
        zend_string_release(property_x_name);

        return class_entry;
} 

But I expected this output instead:

Double quotes need to be escaped

PHP Version

PHP 8.4.14 (cli) (built: Dec  1 2025 12:04:28) (ZTS DEBUG)
Copyright (c) The PHP Group
Zend Engine v4.4.14, Copyright (c) Zend Technologies

Operating System

No response

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions