Skip to content

Function autoloading #425

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

Closed
wants to merge 15 commits into from
Closed
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
2 changes: 1 addition & 1 deletion Zend/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ libZend_la_SOURCES=\
zend_default_classes.c \
zend_iterators.c zend_interfaces.c zend_exceptions.c \
zend_strtod.c zend_closures.c zend_float.c zend_string.c zend_signal.c \
zend_generators.c
zend_generators.c zend_autoload.c

libZend_la_LDFLAGS =
libZend_la_LIBADD = @ZEND_EXTRA_LIBS@
Expand Down
26 changes: 26 additions & 0 deletions Zend/tests/use_const/alias.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
aliasing imported constants to resolve naming conflicts
--FILE--
<?php

namespace foo {
const baz = 42;
}

namespace bar {
const baz = 43;
}

namespace {
use const foo\baz as foo_baz,
bar\baz as bar_baz;
var_dump(foo_baz);
var_dump(bar_baz);
echo "Done\n";
}

?>
--EXPECT--
int(42)
int(43)
Done
22 changes: 22 additions & 0 deletions Zend/tests/use_const/basic.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
import namespaced constant
--FILE--
<?php

namespace foo\bar {
const baz = 42;
const qux = 43;
}

namespace {
use const foo\bar\baz, foo\bar\qux;
var_dump(baz);
var_dump(qux);
echo "Done\n";
}

?>
--EXPECT--
int(42)
int(43)
Done
12 changes: 12 additions & 0 deletions Zend/tests/use_const/case_sensivity.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
importing const with same name but different case
--FILE--
<?php

namespace {
use const foo\bar;
use const foo\BAR;
}

?>
--EXPECT--
21 changes: 21 additions & 0 deletions Zend/tests/use_const/conflicting_use.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
use const statements with conflicting names
--FILE--
<?php

namespace foo {
const baz = 42;
}

namespace bar {
const baz = 42;
}

namespace {
use const foo\baz, bar\baz;
echo "Done\n";
}

?>
--EXPECTF--
Fatal error: Cannot use bar\baz as baz because the name is already in use in %s on line %d
18 changes: 18 additions & 0 deletions Zend/tests/use_const/conflicting_use_alias.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
use and use const with the same alias
--FILE--
<?php

namespace {
const foo = 'foo';
}

namespace x {
use foo as bar;
use const foo as bar;
var_dump(bar);
}

?>
--EXPECT--
string(3) "foo"
14 changes: 14 additions & 0 deletions Zend/tests/use_const/define_imported.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
defining const with same name as imported should fail
--FILE--
<?php

namespace {
use const foo\bar;

const bar = 42;
}

?>
--EXPECTF--
Fatal error: Cannot declare const bar because the name is already in use in %s on line %d
14 changes: 14 additions & 0 deletions Zend/tests/use_const/define_imported_before.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
using const with same name as defined should fail
--FILE--
<?php

namespace {
const bar = 42;

use const foo\bar;
}

?>
--EXPECTF--
Fatal error: Cannot use const foo\bar as bar because the name is already in use in %s on line %d
5 changes: 5 additions & 0 deletions Zend/tests/use_const/includes/foo_bar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

namespace foo;

const bar = 'local bar';
5 changes: 5 additions & 0 deletions Zend/tests/use_const/includes/foo_php_version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

namespace foo;

const PHP_VERSION = 42;
3 changes: 3 additions & 0 deletions Zend/tests/use_const/includes/global_bar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

const bar = 'global bar';
3 changes: 3 additions & 0 deletions Zend/tests/use_const/includes/global_baz.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

const baz = NULL;
14 changes: 14 additions & 0 deletions Zend/tests/use_const/no_global_fallback.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
non-existent imported constants should not be looked up in the global table
--FILE--
<?php

require 'includes/global_baz.php';

use const foo\bar\baz;
var_dump(baz);

?>
--EXPECTF--
Notice: Use of undefined constant baz - assumed 'baz' in %s on line %d
string(3) "baz"
12 changes: 12 additions & 0 deletions Zend/tests/use_const/self_parent.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Allow self and parent in use const statement
--FILE--
<?php

namespace {
use const self as foo;
use const parent as bar;
}

?>
--EXPECT--
16 changes: 16 additions & 0 deletions Zend/tests/use_const/shadow_core.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
shadowing a global core constant with a local version
--FILE--
<?php

require 'includes/foo_php_version.php';

use const foo\PHP_VERSION;

var_dump(PHP_VERSION);
echo "Done\n";

?>
--EXPECTF--
int(42)
Done
25 changes: 25 additions & 0 deletions Zend/tests/use_const/shadow_global.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
shadowing a global constant with a local version
--FILE--
<?php

namespace {
require 'includes/global_bar.php';
require 'includes/foo_bar.php';
}

namespace {
var_dump(bar);
}

namespace {
use const foo\bar;
var_dump(bar);
echo "Done\n";
}

?>
--EXPECT--
string(10) "global bar"
string(9) "local bar"
Done
30 changes: 30 additions & 0 deletions Zend/tests/use_function/alias.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--TEST--
aliasing imported functions to resolve naming conflicts
--FILE--
<?php

namespace foo {
function baz() {
return 'foo.baz';
}
}

namespace bar {
function baz() {
return 'bar.baz';
}
}

namespace {
use function foo\baz as foo_baz,
bar\baz as bar_baz;
var_dump(foo_baz());
var_dump(bar_baz());
echo "Done\n";
}

?>
--EXPECT--
string(7) "foo.baz"
string(7) "bar.baz"
Done
26 changes: 26 additions & 0 deletions Zend/tests/use_function/basic.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
import namespaced function
--FILE--
<?php

namespace foo\bar {
function baz() {
return 'foo.bar.baz';
}
function qux() {
return baz();
}
}

namespace {
use function foo\bar\baz, foo\bar\qux;
var_dump(baz());
var_dump(qux());
echo "Done\n";
}

?>
--EXPECT--
string(11) "foo.bar.baz"
string(11) "foo.bar.baz"
Done
13 changes: 13 additions & 0 deletions Zend/tests/use_function/case_insensivity.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
importing function with same name but different case should fail
--FILE--
<?php

namespace {
use function foo\bar;
use function foo\BAR;
}

?>
--EXPECTF--
Fatal error: Cannot use foo\BAR as BAR because the name is already in use in %s on line %d
25 changes: 25 additions & 0 deletions Zend/tests/use_function/conflicting_use.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
use function statements with conflicting names
--FILE--
<?php

namespace foo {
function baz() {
return 'foo.baz';
}
}

namespace bar {
function baz() {
return 'bar.baz';
}
}

namespace {
use function foo\baz, bar\baz;
echo "Done\n";
}

?>
--EXPECTF--
Fatal error: Cannot use bar\baz as baz because the name is already in use in %s on line %d
20 changes: 20 additions & 0 deletions Zend/tests/use_function/conflicting_use_alias.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
use and use function with the same alias
--FILE--
<?php

namespace {
function foo() {
return 'foo';
}
}

namespace x {
use foo as bar;
use function foo as bar;
var_dump(bar());
}

?>
--EXPECT--
string(3) "foo"
23 changes: 23 additions & 0 deletions Zend/tests/use_function/conflicting_use_const_alias.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
use const and use function with the same alias
--FILE--
<?php

namespace {
const foo = 'foo.const';
function foo() {
return 'foo.function';
}
}

namespace x {
use const foo as bar;
use function foo as bar;
var_dump(bar);
var_dump(bar());
}

?>
--EXPECT--
string(9) "foo.const"
string(12) "foo.function"
14 changes: 14 additions & 0 deletions Zend/tests/use_function/define_imported.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
defining function with same name as imported should fail
--FILE--
<?php

namespace {
use function foo\bar;

function bar() {}
}

?>
--EXPECTF--
Fatal error: Cannot declare function bar because the name is already in use in %s on line %d
Loading