<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/userlandnaming.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'userlandnaming.tips.php',
    1 => 'Tips',
    2 => 'Tips',
  ),
  'up' => 
  array (
    0 => 'userlandnaming.php',
    1 => 'Userland Naming Guide',
  ),
  'prev' => 
  array (
    0 => 'userlandnaming.rules.php',
    1 => 'Rules',
  ),
  'next' => 
  array (
    0 => 'about.php',
    1 => 'About the manual',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'appendices/userlandnaming.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="userlandnaming.tips" class="section">
  <h2 class="title">Tips</h2>
  <p class="para">
   In order to write future-proof code, it is recommended that you don&#039;t
   place many variables, functions or classes in the global namespace. This will
   prevent naming conflicts with 3rd party code as well as possible
   future additions to the language.
  </p>
  <p class="para">
   One common way to prevent naming conflicts of functions and classes is to
   add them to their own dedicated
   <a href="language.namespaces.php" class="link">namespace</a>.
  </p>
  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">namespace </span><span style="color: #0000BB">MyProject</span><span style="color: #007700">;<br /><br />function </span><span style="color: #0000BB">my_function</span><span style="color: #007700">() {<br />    return </span><span style="color: #0000BB">true</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">\MyProject\my_function</span><span style="color: #007700">();</span></span></code></div>
   </div>

  </div>
  <p class="para">
   This still needs you to keep track of already used namespaces, but once you
   have decided on a namespace you will be using you can add all functions and
   classes to it without having to think about conflicts again.
  </p>
  <p class="para">
   It is considered best practice to limit the number of variables added to
   the global scope in order to prevent naming conflicts with 3rd party
   code.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <strong>Variable scoping</strong><br />
   <p class="para">
    Because of PHP&#039;s <a href="language.variables.scope.php" class="link">scoping rules</a>
    variables defined inside functions and methods are not in the global scope
    and as such cannot conflict with other variables defined in the global scope.
   </p>
  </p></blockquote>
 </div><?php manual_footer($setup); ?>