Skip to content

registerlocalnamespace.xml Fix typos and amend return type - #5490

Merged
lacatoire merged 2 commits into
php:masterfrom
mmalferov:patch-58
Aug 31, 2026
Merged

registerlocalnamespace.xml Fix typos and amend return type#5490
lacatoire merged 2 commits into
php:masterfrom
mmalferov:patch-58

Conversation

@mmalferov

Copy link
Copy Markdown
Member

No description provided.

@mmalferov mmalferov changed the title registerlocalnamespace.xml Fix typo registerlocalnamespace.xml Fix typo and amend return type Apr 13, 2026
@mmalferov

mmalferov commented Apr 13, 2026

Copy link
Copy Markdown
Member Author

Based on the actual behavior and the source code, the method returns Yaf_Loader|false.

<?php

$loader = Yaf_Loader::getInstance();

// Returns Yaf_Loader instance
$result = $loader->registerLocalNamespace("Prefix");
var_dump($result); // object(Yaf_Loader)

// Returns false on invalid input
$result = @$loader->registerLocalNamespace(null);
var_dump($result); // bool(false)

Source code (yaf_loader.c):

PHP_METHOD(yaf_loader, registerLocalNamespace) {
	zval *namespaces;
	zend_string *path = NULL;

	if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|S", &namespaces, &path) == FAILURE) {
		return;
	}

	if (IS_STRING == Z_TYPE_P(namespaces)) {
		if (yaf_loader_register_namespace(Z_YAFLOADEROBJ_P(getThis()), Z_STR_P(namespaces), path)) {
			RETURN_ZVAL(getThis(), 1, 0);
		}
	} else if (IS_ARRAY == Z_TYPE_P(namespaces)) {
		if (yaf_loader_register_namespace_multi(Z_YAFLOADEROBJ_P(getThis()), namespaces)) {
			RETURN_ZVAL(getThis(), 1, 0);
		}
	} else {
		php_error_docref(NULL, E_WARNING, "Invalid parameters provided, must be a string, or an array");
	}

	RETURN_FALSE;
}

@mmalferov

Copy link
Copy Markdown
Member Author

And the same:

<?php

$loader = Yaf_Loader::getInstance();

$result = $loader->registerNamespace(namespace: "App\Fake", path: "path"); // Not 'namespaces' that lead to the fatal error
var_dump($result); // object(Yaf_Loader)

$result = @$loader->registerNamespace(null, null);
var_dump($result); // bool(false)

@mmalferov mmalferov changed the title registerlocalnamespace.xml Fix typo and amend return type registerlocalnamespace.xml Fix typos and amend return type Apr 14, 2026
Comment thread reference/yaf/yaf_loader/registerlocalnamespace.xml Outdated
Comment thread reference/yaf/yaf_loader/registernamespace.xml Outdated
Comment thread reference/yaf/yaf_loader/registernamespace.xml Outdated
Comment thread reference/yaf/yaf_loader/registerlocalnamespace.xml
Comment thread reference/yaf/yaf_loader/registerlocalnamespace.xml
Comment thread reference/yaf/yaf_loader/registerlocalnamespace.xml Outdated
Comment thread reference/yaf/yaf_loader/registerlocalnamespace.xml Outdated
Comment thread reference/yaf/yaf_loader/registerlocalnamespace.xml Outdated
Comment thread reference/yaf/yaf_loader/registerlocalnamespace.xml Outdated
Comment thread reference/yaf/yaf_loader/registerlocalnamespace.xml Outdated
Comment thread reference/yaf/yaf_loader/registerlocalnamespace.xml Outdated
Comment thread reference/yaf/yaf_loader/registernamespace.xml Outdated
Comment thread reference/yaf/yaf_loader/registernamespace.xml Outdated
Comment thread reference/yaf/yaf_loader/registernamespace.xml Outdated
Comment thread reference/yaf/yaf_loader/registernamespace.xml Outdated
Comment thread reference/yaf/yaf_loader/registernamespace.xml Outdated
Comment thread reference/yaf/yaf_loader/registernamespace.xml Outdated
Comment thread reference/yaf/yaf_loader/registerlocalnamespace.xml Outdated
Comment thread reference/yaf/yaf_loader/registerlocalnamespace.xml Outdated
Comment thread reference/yaf/yaf_loader/registernamespace.xml Outdated
Comment thread reference/yaf/yaf_loader/registerlocalnamespace.xml Outdated
Comment thread reference/yaf/yaf_loader/registerlocalnamespace.xml Outdated
Comment thread reference/yaf/yaf_route_regex/construct.xml Outdated
Comment thread reference/yaf/yaf_route_regex/construct.xml Outdated
Comment thread reference/yaf/yaf_route_regex/construct.xml Outdated
Comment thread reference/yaf/yaf_loader/registernamespace.xml Outdated
Comment thread reference/yaf/yaf_loader/registernamespace.xml Outdated
Comment thread reference/yaf/yaf_route_regex/construct.xml Outdated
Comment thread reference/yaf/yaf_loader/registerlocalnamespace.xml Outdated
@mmalferov mmalferov closed this Aug 10, 2026
@mmalferov
mmalferov deleted the patch-58 branch August 10, 2026 08:41
@mmalferov
mmalferov restored the patch-58 branch August 10, 2026 08:50
@mmalferov mmalferov reopened this Aug 10, 2026
Comment thread reference/yaf/yaf_route_regex/construct.xml Outdated
Comment thread reference/yaf/yaf_loader/registerlocalnamespace.xml Outdated

@lacatoire lacatoire left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmalferov could you rebase ?

@lacatoire
lacatoire force-pushed the patch-58 branch 2 times, most recently from 29151ae to b1b28ce Compare August 31, 2026 10:56
mmalferov and others added 2 commits August 31, 2026 13:13
- describe what the constructor does, the description was an empty para
- declare map, verify and reverse as nullable with a null default, which
  is what zend_parse_parameters_throw(..., "Sa|a!a!S!", ...) says
- attribute the false return to Yaf_Route_Regex::route() rather than to
  the class, and fix "if doesn't matched"
- spell out module, controller and action instead of "m/c/a", which the
  manual never expands, and say that a route entry starting with ":" is
  resolved against the parameters map produces
- describe what map really does: it selects which numeric captures become
  request parameters, an unlisted one is discarded, and named capture
  groups are added under their own name without being listed
- document verify, which was an empty para: it is stored on the route and
  never consulted while routing
- fill the empty returnvalues para with the wording the sibling
  constructor pages use
- fix the capture group in the three product examples: the + sat outside
  the group, so "#^/product/([^/]+)/([^/])+#" captured a single character
  and the documented $request->getParam("id") returned "4" for an id of
  "1234"
- give the four examples distinct titles and align their comments with
  the ones in yaf_route_regex/route.xml
- add Yaf_Route_Regex::route and ::assemble to the see also list

Rebased onto the Yaf documentation revision in php#5809, which converted the
note on the reverse parameter to a simpara; that conversion is kept.

Sources
- routes/yaf_route_regex.c: the zpp string in the constructor; the map
  handling in yaf_route_regex_match(), where a numeric capture with no
  map entry is dropped and a named group is kept unconditionally; the
  ":" branch of yaf_route_regex_route(); the absence of any read of
  regex->verify
- verified with php 8.5.4: preg_match("#^/product/([^/]+)/([^/])+#",
  "/product/php-book/1234", $m) gives $m[2] === "4"
The Yaf documentation revision in php#5809 rewrote both loader pages and
already carries most of what this pull request proposed there. Four
things it did not get right are fixed here.

registerNamespace documented its first parameter as name_prefix. That
name comes from yaf_loader.stub.php, and nothing in the extension
includes the arginfo generated from it; the registered arginfo is the
hand-written yaf_loader_regnamespace_arginfo, which names the parameter
namespace, as the alias target page already documented. A named argument
using name_prefix fails.

The return union carried null, which no longer has a reachable path: the
only bare return is after a zend_parse_parameters failure, and since PHP
8.0 that throws instead of returning. Both pages already said in their
return values section that the method returns the instance or false.

<type>string|array</type> is not how the manual writes a union type. It
occurred twice in the whole of reference/, both introduced by that
commit, against more than three thousand occurrences of
<type class="union">. Likewise <initializer>null</initializer> against
&null;.

The prefix matching rule is worth stating, since the obvious reading of
"prefix" is wrong: yaf_loader_register_namespace() strips a leading
backslash and then splits the name on backslash and underscore, so a
registered prefix only matches at one of those boundaries. Note the
claim is deliberately limited to the lookup side: a class name is
sanitised with backslashes rewritten to underscores before resolution,
but the registration path scans for a backslash across the whole string
before falling back to an underscore, so the two delimiters are not
interchangeable in a registered prefix.

Sources
- yaf_loader.c, yaf_loader_regnamespace_arginfo and the PHP_MALIAS that
  registers registerNamespace against it
- yaf_loader.c, yaf_loader_register_namespace(), the *name == '\\' skip
  and the memchr on '\\' then '_'
- yaf_loader.c, yaf_loader_sanitize_name() and
  yaf_loader_resolve_namespace(), which split on '_' alone
@lacatoire
lacatoire merged commit 052c737 into php:master Aug 31, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants