[php-src] Issue #22169: gen_stub.php generated wrong C string

[email protected] (matyhtf) Thu, 28 May 2026 12:05:19 +0000
Newsgroups php.bugs
Message-ID <[email protected]>
Issue: https://github.com/php/php-src/issues/22169
Author: matyhtf

### Description

The following code:

```php
<?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
```

```c
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

```plain
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_