@@ -160,8 +160,7 @@ Changes in the Zend Engine 2.0
160
160
defaulting to the current global one. The current namespace may
161
161
be changed on a file-by-file basis. Symbols in other namespaces
162
162
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.
165
164
166
165
Namespaces and classes are the same with the Zend Engine 2.0,
167
166
except that you can't instantiate a namespace with "new". This
@@ -256,36 +255,53 @@ Changes in the Zend Engine 2.0
256
255
This prints "foobar" two times, since a bar() method exists
257
256
in the current namespace.
258
257
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 .
261
260
262
- * import statement.
261
+ Example:
263
262
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
+ }
266
268
267
- Example:
269
+ class MyClass2 {
270
+ function hello() {
271
+ print "Hello, World in MyClass2\n";
272
+ }
273
+ }
274
+ }
268
275
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:
274
283
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
+ }
278
295
}
279
- }
280
- }
281
296
282
- import function hello, class MyClass2 from MyClass;
297
+ import class * from MyOuterClass;
298
+ import function func2 from MyOuterClass::MyInnerClass;
283
299
284
- MyClass2::hello ();
285
- hello ();
286
- ?>
300
+ MyInnerClass::func1 ();
301
+ func2 ();
302
+ ?>
287
303
288
- Old code that has no user-defined function 'import' will run
304
+ Old code that does not take advantage of namespaces will run
289
305
without modifications.
290
306
291
307
* Unified Constructors.
0 commit comments