Ads Inside Post

Search in This Blog

namespace in php

namespace in php

<?php
namespace foo;
class Robot {
    static function says() {echo 'I am Terminator!';}
    }
?>
  
<?php
namespace bar;
class RoboCop {
    static function says() {echo 'I am Robocop!';}
    }
?>
  
<?php namespace terminate;
    class Terminator {
    static function says() {echo 'Terminator';}  }
?>

<?php namespace computer;
    class Comp {
    static function show() {echo 'I am computer';}
    function laptop() { echo "this is laptop ";}
    }
?>

  
<?php

namespace realexample;
//use foo as robo;
//use bar as roboc;
//use terminate;
//echo robo\Robot::says(), "<br />\n";
//echo roboc\RoboCop::says(), "<br />\n";
//echo terminate\Terminator::says(), "<br />\n";


echo \foo\Robot::says(), "<br />\n";
echo \bar\RoboCop::says(), "<br />\n";
echo \terminate\Terminator::says(), "<br />\n";
echo \computer\Comp::show(), "<br />\n";
$comp = new \computer\Comp();
$comp->laptop();
 

  ?>