<em id="gxj5d"></em>
          <delect id="gxj5d"><ins id="gxj5d"><form id="gxj5d"></form></ins></delect>
          <dl id="gxj5d"></dl><em id="gxj5d"></em>
          <div id="gxj5d"><tr id="gxj5d"></tr></div>

          <em id="gxj5d"><ol id="gxj5d"><mark id="gxj5d"></mark></ol></em>

                <dl id="gxj5d"><ol id="gxj5d"></ol></dl><em id="gxj5d"></em>
                <em id="gxj5d"><ol id="gxj5d"></ol></em>
                <sup id="gxj5d"><menu id="gxj5d"></menu></sup>
                    <span id="gxj5d"><form id="gxj5d"><wbr id="gxj5d"></wbr></form></span><dl id="gxj5d"><ins id="gxj5d"></ins></dl>
                      <div id="gxj5d"><tr id="gxj5d"></tr></div>
                      <em id="gxj5d"></em>

                      <em id="gxj5d"><ol id="gxj5d"><thead id="gxj5d"></thead></ol></em>
                          add a note add a note

                          User Contributed Notes 5 notes

                          up
                          164
                          Anonymous
                          8 years ago
                          The keyword 'use' has two different applications, but the reserved word table links to here.

                          It can apply to namespace constucts:

                          file1:
                          <?php namespace foo;
                            class
                          Cat {
                              static function
                          says() {echo 'meoow';}  } ?>

                          file2:
                          <?php namespace bar;
                            class
                          Dog {
                              static function
                          says() {echo 'ruff';}  } ?>

                          file3:
                          <?php namespace animate;
                            class
                          Animal {
                              static function
                          breathes() {echo 'air';}  } ?>

                          file4:
                          <?php namespace fub;
                            include
                          'file1.php';
                            include
                          'file2.php';
                            include
                          'file3.php';
                            use
                          foo as feline;
                            use
                          bar as canine;
                            use
                          animate;
                            echo \
                          feline\Cat::says(), "<br />\n";
                            echo \
                          canine\Dog::says(), "<br />\n";
                            echo \
                          animate\Animal::breathes(), "<br />\n"?>

                          Note that
                          felineCat::says()
                          should be
                          \feline\Cat::says()
                          (and similar for the others)
                          but this comment form deletes the backslash (why???)

                          The 'use' keyword also applies to closure constructs:

                          <?php function getTotal($products_costs, $tax)
                              {
                                 
                          $total = 0.00;
                                 
                                 
                          $callback =
                                      function (
                          $pricePerItem) use ($tax, &$total)
                                      {
                                         
                                         
                          $total += $pricePerItem * ($tax + 1.0);
                                      };
                                 
                                 
                          array_walk($products_costs, $callback);
                                  return
                          round($total, 2);
                              }
                          ?>
                          up
                          20
                          Anonymous
                          3 years ago
                          Tested on PHP 7.0.5, Windows
                          The line "use animate;" equals the line "use animate as animate;"
                          but the "use other\animate;" equals "use other\animate as animate;"

                          file1:
                          <?php namespace foo;
                            class
                          Cat {
                              static function
                          says() {echo 'meoow';}  } ?>

                          file2:
                          <?php namespace bar;
                            class
                          Dog {
                              static function
                          says() {echo 'ruff';}  } ?>

                          file3:
                          <?php namespace other\animate;
                            class
                          Animal {
                              static function
                          breathes() {echo 'air';}  } ?>

                          file4:
                          <?php namespace fub;
                            include
                          'file1.php';
                            include
                          'file2.php';
                            include
                          'file3.php';
                            use
                          foo as feline;
                            use
                          bar as canine;
                            use
                          other\animate;       //use other\animate as animate;
                           
                          echo feline\Cat::says(), "<br />\n";
                            echo
                          canine\Dog::says(), "<br />\n";
                            echo \
                          animate\Animal::breathes(), "<br />\n"?>
                          up
                          8
                          varuninorbit at yahoo dot co dot in
                          3 years ago
                          here is a simple example to use namespace

                          <?php

                          namespace app\a{
                              class
                          one{
                                 public static function
                          _1(){
                                  echo
                          'a one _1<br>';
                                 }
                              }
                          }

                          namespace
                          app\b{
                              class
                          one{
                                  public static function
                          _2(){
                                      echo
                          'b one _2<br>';
                                  }
                              }
                          }

                          namespace
                          app{

                              echo
                          a\one::_1();
                              echo
                          b\one::_2();
                              echo
                          a\two::_1();
                          }

                          namespace
                          app\a{
                              class
                          two{
                                 public static function
                          _1(){
                                  echo
                          'a two _1<br>';
                                 }
                              }
                          }

                          prints
                          a one _1
                          b one _2
                          a two _1
                          up
                          4
                          davidkennedy85 at gmail dot com
                          4 years ago
                          In addition to using namespaces and closures, the use keyword has another new meaning as of PHP 5.4 - using traits:

                          <?php
                          trait Hello {
                              public function
                          sayHello() {
                                  echo
                          'Hello ';
                              }
                          }

                          trait
                          World {
                              public function
                          sayWorld() {
                                  echo
                          'World';
                              }
                          }

                          class
                          MyHelloWorld {
                              use
                          Hello, World;
                              public function
                          sayExclamationMark() {
                                  echo
                          '!';
                              }
                          }

                          $o = new MyHelloWorld();
                          $o->sayHello();
                          $o->sayWorld();
                          $o->sayExclamationMark();
                          ?>

                          More info here: http://php.net/manual/en/language.oop5.traits.php
                          up
                          -50
                          Ronald W
                          4 years ago
                          <?php
                          // multiple namespaces in a single file:

                          namespace foo{
                            class
                          Cat {
                              static function
                          says() {echo 'meoow';}  }
                          }

                          namespace
                          bar{
                            class
                          Dog {
                              static function
                          says() {echo 'ruff';}  } 
                            class
                          Cat {
                              static function
                          says() {echo 'meowi';}  }
                            class
                          Mouse {     //nonstatic function
                             
                          function says() {echo 'Come and get me ;)';}  }
                          }

                          namespace
                          animate{
                            class
                          Animal {
                              static function
                          breathes() {echo 'air';}  }
                          }

                          namespace{       
                          // No Namespace: global code
                           
                          use foo as feline;
                            use
                          bar as canine;
                            use
                          bar\Mouse as MouseOnly;
                            use
                          animate;
                            echo
                          animate\Animal::breathes(), "<br />\n"
                            echo
                          feline\Cat::says(), "<br />\n"; //not starting with a slash!
                           
                          echo canine\Cat::says(), "<br />\n";
                            echo
                          canine\Dog::says(), "<br />\n";
                           
                          //any of the three following lines work:
                            // $micky=new bar\Mouse();
                            // $micky=new canine\Mouse();
                           
                          $micky=new test();
                            echo
                          $micky->says();
                          }
                          ?>
                          To Top 宁夏11选5开奖直播

                                <em id="gxj5d"></em>
                                  <delect id="gxj5d"><ins id="gxj5d"><form id="gxj5d"></form></ins></delect>
                                  <dl id="gxj5d"></dl><em id="gxj5d"></em>
                                  <div id="gxj5d"><tr id="gxj5d"></tr></div>

                                  <em id="gxj5d"><ol id="gxj5d"><mark id="gxj5d"></mark></ol></em>

                                        <dl id="gxj5d"><ol id="gxj5d"></ol></dl><em id="gxj5d"></em>
                                        <em id="gxj5d"><ol id="gxj5d"></ol></em>
                                        <sup id="gxj5d"><menu id="gxj5d"></menu></sup>
                                            <span id="gxj5d"><form id="gxj5d"><wbr id="gxj5d"></wbr></form></span><dl id="gxj5d"><ins id="gxj5d"></ins></dl>
                                              <div id="gxj5d"><tr id="gxj5d"></tr></div>
                                              <em id="gxj5d"></em>

                                              <em id="gxj5d"><ol id="gxj5d"><thead id="gxj5d"></thead></ol></em>

                                                        <em id="gxj5d"></em>
                                                          <delect id="gxj5d"><ins id="gxj5d"><form id="gxj5d"></form></ins></delect>
                                                          <dl id="gxj5d"></dl><em id="gxj5d"></em>
                                                          <div id="gxj5d"><tr id="gxj5d"></tr></div>

                                                          <em id="gxj5d"><ol id="gxj5d"><mark id="gxj5d"></mark></ol></em>

                                                                <dl id="gxj5d"><ol id="gxj5d"></ol></dl><em id="gxj5d"></em>
                                                                <em id="gxj5d"><ol id="gxj5d"></ol></em>
                                                                <sup id="gxj5d"><menu id="gxj5d"></menu></sup>
                                                                    <span id="gxj5d"><form id="gxj5d"><wbr id="gxj5d"></wbr></form></span><dl id="gxj5d"><ins id="gxj5d"></ins></dl>
                                                                      <div id="gxj5d"><tr id="gxj5d"></tr></div>
                                                                      <em id="gxj5d"></em>

                                                                      <em id="gxj5d"><ol id="gxj5d"><thead id="gxj5d"></thead></ol></em>