Skip to content

Reset seen symbols when ending namespace #15244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ PHP NEWS
. Passing E_USER_ERROR to trigger_error() is now deprecated. (Girgias)
. Fixed bug GH-15292 (Dynamic AVX detection is broken for MSVC). (nielsdos)
. Using "_" as a class name is now deprecated. (Girgias)
. Exiting a namespace now clears seen symbols. (ilutov)

- Curl:
. Added constants CURL_HTTP_VERSION_3 (libcurl 7.66) and CURL_HTTP_VERSION_3ONLY
Expand Down
4 changes: 4 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ PHP 8.4 UPGRADE NOTES
RFC: https://wiki.php.net/rfc/deprecated_attribute
. Implemented property hooks.
RFC: https://wiki.php.net/rfc/property-hooks
. Exiting a namespace now clears seen symbols. This allows using a symbol in a
namespace block, even if a previous namespace block declared a symbol with
the same name.
See Zend/tests/use_function/ns_end_resets_seen_symbols_1.phpt.

- Curl:
. curl_version() returns an additional feature_list value, which is an
Expand Down
58 changes: 58 additions & 0 deletions Zend/tests/use_function/ns_end_resets_seen_symbols_1.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
--TEST--
Namespace end resets seen function symbols
--FILE--
<?php

namespace {
function f() {
echo __FUNCTION__, "\n";
}
f();
}

namespace Ns {
function f() {
echo __FUNCTION__, "\n";
}
f();
}

namespace {
use function Ns\f;
f();
}

namespace Ns {
use function f;
f();
}

namespace {
f();
}

namespace Ns {
f();
}

namespace {
use function f;
f();
}

namespace Ns {
use function Ns\f;
f();
}

?>
--EXPECTF--
Warning: The use statement with non-compound name 'f' has no effect in %s on line 36
f
Ns\f
Ns\f
f
f
Ns\f
f
Ns\f
62 changes: 62 additions & 0 deletions Zend/tests/use_function/ns_end_resets_seen_symbols_2.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
--TEST--
Namespace end resets seen class symbols
--FILE--
<?php

namespace {
class C {}
var_dump(new C);
}

namespace Ns {
class C {}
var_dump(new C);
}

namespace {
use Ns\C;
var_dump(new C);
}

namespace Ns {
use C;
var_dump(new C);
}

namespace {
var_dump(new C);
}

namespace Ns {
var_dump(new C);
}

namespace {
use C;
var_dump(new C);
}

namespace Ns {
use Ns\C;
var_dump(new C);
}

?>
--EXPECTF--
Warning: The use statement with non-compound name 'C' has no effect in %s on line 32
object(C)#%d (0) {
}
object(Ns\C)#1 (0) {
}
object(Ns\C)#1 (0) {
}
object(C)#%d (0) {
}
object(C)#%d (0) {
}
object(Ns\C)#1 (0) {
}
object(C)#%d (0) {
}
object(Ns\C)#1 (0) {
}
2 changes: 2 additions & 0 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ static void zend_reset_import_tables(void) /* {{{ */
efree(FC(imports_const));
FC(imports_const) = NULL;
}

zend_hash_clean(&FC(seen_symbols));
}
/* }}} */

Expand Down
Loading