Merge pull request #224 from lastorset/gh-pages

Clarify global-namespace explanation
This commit is contained in:
Phil Sturgeon
2012-12-14 11:22:41 -08:00

View File

@@ -104,8 +104,8 @@ function test($a)
## Global namespace ## Global namespace
While using namespaces, you may find your code being executed in the wrong scope for internal methods. To fix this, When using namespaces, you may find that internal functions are hidden by functions you wrote. To fix this,
define the method globally by using a backslash before the method. refer to the global function by using a backslash before the function name.
{% highlight php %} {% highlight php %}
<?php <?php
@@ -113,14 +113,14 @@ namespace phptherightway;
function fopen() function fopen()
{ {
$file = \fopen(); // our function name is the same as an internal function $file = \fopen(); // Our function name is the same as an internal function.
// execute globally by adding '\'. // Execute the function from the global space by adding '\'.
} }
function array() function array()
{ {
$iterator = new \ArrayIterator(); // ArrayIterator is an internal class. Using it without a backslash $iterator = new \ArrayIterator(); // ArrayIterator is an internal class. Using its name without a backslash
// will execute it within the namespace scope // will attempt to resolve it within your namespace.
} }
{% endhighlight %} {% endhighlight %}