Skip to content

Commit 0e17eea

Browse files
Add another 'import' example and merge 'import' section into 'Namespaces' section.
1 parent cc891da commit 0e17eea

File tree

1 file changed

+39
-23
lines changed

1 file changed

+39
-23
lines changed

Zend/ZEND_CHANGES

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ Changes in the Zend Engine 2.0
160160
defaulting to the current global one. The current namespace may
161161
be changed on a file-by-file basis. Symbols in other namespaces
162162
than the current one may be referenced using a new namespace
163-
operator. It is possible to "import" symbols from one namespace
164-
into another.
163+
operator.
165164

166165
Namespaces and classes are the same with the Zend Engine 2.0,
167166
except that you can't instantiate a namespace with "new". This
@@ -256,36 +255,53 @@ Changes in the Zend Engine 2.0
256255
This prints "foobar" two times, since a bar() method exists
257256
in the current namespace.
258257

259-
Old code that does not take advantage of namespaces will run
260-
without modifications.
258+
* It is possible to "import" symbols from one namespace into
259+
another.
261260

262-
* import statement.
261+
Example:
263262

264-
With the new import statement it is possible to import classes
265-
and methods from other classes (namespaces) to the current scope.
263+
<?php
264+
class MyClass {
265+
function hello() {
266+
print "Hello, World\n";
267+
}
266268

267-
Example:
269+
class MyClass2 {
270+
function hello() {
271+
print "Hello, World in MyClass2\n";
272+
}
273+
}
274+
}
268275

269-
<?php
270-
class MyClass {
271-
function hello() {
272-
print "Hello, World\n";
273-
}
276+
import function hello, class MyClass2 from MyClass;
277+
278+
MyClass2::hello();
279+
hello();
280+
?>
281+
282+
Example:
274283

275-
class MyClass2 {
276-
function hello() {
277-
print "Hello, World in MyClass2\n";
284+
<?php
285+
class MyOuterClass {
286+
class MyInnerClass {
287+
function func1() {
288+
print "func1()\n";
289+
}
290+
291+
function func2() {
292+
print "func2()\n";
293+
}
294+
}
278295
}
279-
}
280-
}
281296

282-
import function hello, class MyClass2 from MyClass;
297+
import class * from MyOuterClass;
298+
import function func2 from MyOuterClass::MyInnerClass;
283299

284-
MyClass2::hello();
285-
hello();
286-
?>
300+
MyInnerClass::func1();
301+
func2();
302+
?>
287303

288-
Old code that has no user-defined function 'import' will run
304+
Old code that does not take advantage of namespaces will run
289305
without modifications.
290306

291307
* Unified Constructors.

0 commit comments

Comments
 (0)