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
<methodsynopsis>
<modifier>public</modifier> <type>void</type><methodname>Yaf_Loader::registerLocalNamespace</methodname>
<modifier>public</modifier> <type class="union"><type>Yaf_Loader</type><type>false</type></type><methodname>Yaf_Loader::registerLocalNamespace</methodname>
<methodparam><type>mixed</type><parameter>prefix</parameter></methodparam>
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.

Suggested change
<methodparam><type>mixed</type><parameter>prefix</parameter></methodparam>
<methodparam><type class="union"><type>string</type><type>array</type><
/type><parameter>prefix</parameter></methodparam>

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.

The function only accepts string or array at runtime. Other types trigger an E_WARNING and the function returns false. See here Aligns with the sibling registernamespace.xml which already uses string|array.

<note>
<para>
Yaf still think underline as folder separator.
Yaf still think underscore as folder separator.
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.

Suggested change
Yaf still think underscore as folder separator.
Yaf still thinks underscore as folder separator.

<listitem>
<para>
a string of path, it is better to use abosolute path here for performance
A &string; of path, it is better to use abosolute path here for performance.
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.

Suggested change
A &string; of path, it is better to use abosolute path here for performance.
A &string; of path, it is better to use absolute path here for performance.

<modifier>public</modifier> <type>void</type><methodname>Yaf_Loader::registerLocalNamespace</methodname>
<modifier>public</modifier> <type class="union"><type>Yaf_Loader</type><type>false</type></type><methodname>Yaf_Loader::registerLocalNamespace</methodname>
<methodparam><type>mixed</type><parameter>prefix</parameter></methodparam>
</methodsynopsis>
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.

Suggested change
</methodsynopsis>
<methodparam choice="opt"><type>string</type><parameter>path</parameter></methodparam>
</methodsynopsis>

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.

The function accepts a second optional $path parameter that isn't documented on this page. Per the zpp call "z|S" the function takes one required zval and one optional string, and the proto comment right above the method confirms:
proto public Yaf_Loader::registerLocalNamespace(mixed $namespace, string $path = NULL) Here

The sibling registernamespace.xml already documents $path, which makes sense since both methods are the same C function (PHP_MALIAS).

All class prefix with these prefix will be loaded in local library path.
</para>
</listitem>
</varlistentry>
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.

Suggested change
</varlistentry>
</varlistentry>
<varlistentry>
<term><parameter>path</parameter></term>
<listitem>
<simpara>A &string; of path, it is better to use absolute path here for performance.</simpara>
</listitem>
</varlistentry>

all class prefix with these prefix will be loaded in local library path.
A &string; or an &array; of class name prefix.
All class prefix with these prefix will be loaded in local library path.
</para>
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.

Suggested change
</para>
</simpara>

@@ -49,8 +50,8 @@
<term><parameter>prefix</parameter></term>
<listitem>
<para>
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.

Suggested change
<para>
<simpara>

@@ -60,7 +61,7 @@
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
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.

Suggested change
<para>
<simpara>

<para>
bool
Returns the <classname>Yaf_Loader</classname> instance on success,&return.falseforfailure;.
</para>
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.

Suggested change
</para>
</simpara>

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.

2 participants