Skip to content

registerlocalnamespace.xml Fix typos and amend return type#5490

Open
mmalferov wants to merge 12 commits intophp:masterfrom
mmalferov:patch-58
Open

registerlocalnamespace.xml Fix typos and amend return type#5490
mmalferov wants to merge 12 commits intophp: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
Copy link
Copy Markdown
Member Author

mmalferov commented Apr 13, 2026

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
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.

1 participant