Skip to content

Commit cbb3412

Browse files
committed
Remove some irrelevant code example sections + fix some wording
1 parent 7851430 commit cbb3412

File tree

1 file changed

+16
-67
lines changed

1 file changed

+16
-67
lines changed

docs/source/miscellaneous/stubs.rst

Lines changed: 16 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,6 @@ using the ``@prefer-ref`` PHPDoc tag:
138138
*/
139139
function foo(&$param1, string $param2): string {}
140140
141-
This is going to yield the following arginfo structure:
142-
143-
.. code:: c
144-
145-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_foo, 0, 2, IS_STRING, 0)
146-
ZEND_ARG_INFO(1, param1)
147-
ZEND_ARG_TYPE_INFO(ZEND_SEND_PREFER_REF, param2, IS_STRING, 0)
148-
ZEND_END_ARG_INFO()
149-
150141
*****************************
151142
Generating function entries
152143
*****************************
@@ -260,17 +251,7 @@ The following arginfo file is generated:
260251
{
261252
zend_class_entry *class_entry = zend_register_internal_enum("Number", IS_STRING, class_Number_methods);
262253
263-
zval const_ONE_value;
264-
zend_string *const_ONE_value_str = zend_string_init("one", strlen("one"), 1);
265-
ZVAL_STR(&const_ONE_value, const_ONE_value_str);
266-
zend_string *const_ONE_name = zend_string_init_interned("ONE", sizeof("ONE") - 1, 1);
267-
zend_declare_class_constant_ex(class_entry, const_ONE_name, &const_ONE_value, ZEND_ACC_PUBLIC, NULL);
268-
zend_string_release(const_ONE_name);
269-
270-
zval enum_case_One_value;
271-
zend_string *enum_case_One_value_str = zend_string_init("one", strlen("one"), 1);
272-
ZVAL_STR(&enum_case_One_value, enum_case_One_value_str);
273-
zend_enum_add_case_cstr(class_entry, "One", &enum_case_One_value);
254+
/* ... */
274255
275256
return class_entry;
276257
}
@@ -279,20 +260,7 @@ The following arginfo file is generated:
279260
{
280261
zend_class_entry ce, *class_entry;
281262
282-
INIT_CLASS_ENTRY(ce, "Foo", class_Foo_methods);
283-
class_entry = zend_register_internal_class_ex(&ce, NULL);
284-
285-
zval const_PI_value;
286-
ZVAL_DOUBLE(&const_PI_value, M_PI);
287-
zend_string *const_PI_name = zend_string_init_interned("PI", sizeof("PI") - 1, 1);
288-
zend_declare_typed_class_constant(class_entry, const_PI_name, &const_PI_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_DOUBLE));
289-
zend_string_release(const_PI_name);
290-
291-
zval property_prop_default_value;
292-
ZVAL_UNDEF(&property_prop_default_value);
293-
zend_string *property_prop_name = zend_string_init("prop", sizeof("prop") - 1, 1);
294-
zend_declare_typed_property(class_entry, property_prop_name, &property_prop_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING));
295-
zend_string_release(property_prop_name);
263+
/* ... */
296264
297265
return class_entry;
298266
}
@@ -357,10 +325,7 @@ attribute:
357325
358326
static void register_example_symbols(int module_number)
359327
{
360-
REGISTER_STRING_CONSTANT("FOO", "foo", CONST_PERSISTENT);
361-
REGISTER_DOUBLE_CONSTANT("BAR", M_PI, CONST_PERSISTENT);
362-
363-
zend_add_parameter_attribute(zend_hash_str_find_ptr(CG(function_table), "foo", sizeof("foo") - 1), 0, ZSTR_KNOWN(ZEND_STR_SENSITIVEPARAMETER), 0);
328+
/* ... */
364329
}
365330
366331
Similarly to class registration functions, ``register_example_symbols()`` also has to be called
@@ -444,23 +409,12 @@ Then notice the ``#if (PHP_VERSION_ID >= ...)`` conditions in the generated argi
444409

445410
.. code:: c
446411
447-
static const zend_function_entry class_Number_methods[] = {
448-
ZEND_FE_END
449-
};
450-
451-
static const zend_function_entry class_Foo_methods[] = {
452-
ZEND_ME(Foo, foo, arginfo_class_Foo_foo, ZEND_ACC_PUBLIC)
453-
ZEND_FE_END
454-
};
412+
/* ... */
455413
456414
#if (PHP_VERSION_ID >= 80100)
457415
static zend_class_entry *register_class_Number(void)
458416
{
459-
zend_class_entry *class_entry = zend_register_internal_enum("Number", IS_UNDEF, class_Number_methods);
460-
461-
zend_enum_add_case_cstr(class_entry, "One", NULL);
462-
463-
return class_entry;
417+
/* ... */
464418
}
465419
#endif
466420
@@ -484,7 +438,7 @@ Then notice the ``#if (PHP_VERSION_ID >= ...)`` conditions in the generated argi
484438
return class_entry;
485439
}
486440
487-
The prepocessor conditions are necessary because ``enum``s and ``readonly`` properties are PHP 8.1
441+
The preprocessor conditions are necessary because ``enum``s and ``readonly`` properties are PHP 8.1
488442
features and consequently, they don't exist in PHP 8.0. Therefore, the registration of ``Number`` is
489443
completely omitted, while the ``readonly`` flag is not added for ``Foo::$prop`` below PHP 8.1
490444
versions.
@@ -496,8 +450,8 @@ versions.
496450
A list of functions is maintained for the optimizer in ``Zend/Optimizer/zend_func_infos.h``
497451
containing extra information about the return type and the cardinality of the return value. These
498452
pieces of information can enable more accurate optimizations (i.e. better type inference).
499-
Previously, the file was maintained manually, however since PHP 8.1, ``gen_stub.php`` takes care of
500-
this task by passing the ``--generate-optimizer-info`` option.
453+
Previously, the file was maintained manually, however since PHP 8.1, ``gen_stub.php`` can take care
454+
of this task when the ``--generate-optimizer-info`` option is passed to it.
501455

502456
A function is added to ``zend_func_infos.h`` if either the ``@return`` or the ``@refcount`` PHPDoc
503457
tag supplies more information than what is available based on the return type declaration. By
@@ -514,12 +468,6 @@ An example from the built-in functions:
514468
*/
515469
function get_declared_classes(): array {}
516470
517-
Based on which the following func info entry is provided for the optimizer:
518-
519-
.. code:: c
520-
521-
F1("get_declared_classes", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
522-
523471
Please note that the feature is only available for built-in stubs inside php-src, since currently
524472
there is no way to provide the function list for the optimizer other than overwriting
525473
``zend_func_infos.h`` directly.
@@ -596,27 +544,28 @@ the 3-parameter signatures:
596544

597545
Theoretically, the manual should reflect the exact same signatures which are represented by the
598546
stubs. This is not exactly the case yet for built-in symbols, but ``gen_stub.php`` have multiple
599-
features to automate the process of syncronization.
547+
features to automate the process of synchronization.
600548

601549
First of all, newly added functions or methods can be documented by providing the
602550
``--generate-methodsynopses`` option. E.g. running ``./build/gen_stub.php --generate-methodsynopses
603551
./ext/mbstring ../doc-en/reference/mbstring`` will create a dedicated page for each ``ext/mbstring``
604552
function which is not yet documented, saving them into the
605-
``../doc-en/reference/mbstring/functions`` directory. Since the generated pages are stubs, the
606-
relevant descriptions have to be added, while the irrelevant ones have to be removed.
553+
``../doc-en/reference/mbstring/functions`` directory. Since these are stub pages, many of the
554+
sections are empty by default, so the relevant descriptions have to be added, while the irrelevant
555+
ones have to be removed.
607556

608557
For functions or methods which are already available in the manual, the documented signatures can be
609558
updated by providing the ``--replace-methodsynopses`` option. E.g. running ``./build/gen_stub.php
610559
--replace-methodsynopses ./ ../doc-en/`` will update all the function or method signatures in the
611560
English documentation whose stub counterpart is found.
612561

613-
Class signatures can be updated by providing the ``--replace-classsynopses`` option. E.g. running
614-
``./build/gen_stub.php --replace-classsynopses ./ ../doc-en/`` will update all the class signatures
615-
in the English documentation whose stub counterpart is found.
562+
Class signatures can be updated in the manual by providing the ``--replace-classsynopses`` option.
563+
E.g. running ``./build/gen_stub.php --replace-classsynopses ./ ../doc-en/`` will update all the
564+
class signatures in the English documentation whose stub counterpart is found.
616565

617566
If a symbol is not intended to be documented, the ``@undocumentable`` PHPDoc tag should be added to
618567
it. Doing so will prevent any documentation to be created for the given symbol. In order not to add
619-
a whole stub file not to the manual, the PHPDoc tag should be applied to the file itself. These
568+
a whole stub file to the manual, the PHPDoc tag should be applied to the file itself. These
620569
possibilities are useful for symbols which exist only for testing purposes (e.g. the ones declared
621570
for ``ext/zend_test``), or by some other reason documentation is not possible.
622571

0 commit comments

Comments
 (0)