registerlocalnamespace.xml Fix typos and amend return type - #5490
Merged
Conversation
Member
Author
|
Based on the actual behavior and the source code, the method returns <?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 ( 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;
} |
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) |
lacatoire
reviewed
Apr 22, 2026
lacatoire
reviewed
Apr 22, 2026
lacatoire
reviewed
Apr 22, 2026
lacatoire
reviewed
Apr 22, 2026
lacatoire
reviewed
Apr 22, 2026
lacatoire
reviewed
Apr 22, 2026
lacatoire
reviewed
Apr 22, 2026
lacatoire
reviewed
Apr 22, 2026
lacatoire
reviewed
Apr 22, 2026
lacatoire
reviewed
Jun 8, 2026
lacatoire
reviewed
Jun 8, 2026
lacatoire
reviewed
Jul 22, 2026
lacatoire
reviewed
Jul 22, 2026
lacatoire
reviewed
Jul 22, 2026
lacatoire
reviewed
Jul 22, 2026
lacatoire
reviewed
Jul 22, 2026
lacatoire
reviewed
Jul 22, 2026
lacatoire
reviewed
Jul 22, 2026
lacatoire
reviewed
Jul 22, 2026
lacatoire
reviewed
Jul 22, 2026
lacatoire
reviewed
Jul 22, 2026
lacatoire
reviewed
Jul 22, 2026
lacatoire
reviewed
Jul 22, 2026
lacatoire
reviewed
Jul 22, 2026
lacatoire
reviewed
Jul 22, 2026
lacatoire
reviewed
Jul 22, 2026
lacatoire
reviewed
Jul 22, 2026
lacatoire
reviewed
Jul 22, 2026
lacatoire
reviewed
Jul 22, 2026
lacatoire
reviewed
Aug 24, 2026
lacatoire
reviewed
Aug 24, 2026
lacatoire
requested changes
Aug 24, 2026
lacatoire
left a comment
Member
There was a problem hiding this comment.
@mmalferov could you rebase ?
lacatoire
force-pushed
the
patch-58
branch
2 times, most recently
from
August 31, 2026 10:56
29151ae to
b1b28ce
Compare
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.