Fatal error: Namespace declaration statement has to be the very first statement in the script



  • I can't understand why this mistake is coming. This is the file code where Fatal error: Namespace declaration statement has to be the very first statement in the script in /var/www/html/phpinstagram/phpinstagram/Instagram.php on line 2

    <?
    namespace phpinstagram;
    

    class Instagram {

    /*

    • @var array
      */
      protected $_commands = array();

    /*

    • @var \phpinstagram\Instagram\Client\Communication
      */
      protected $_communication;

    /*

    • @var \phpinstagram\Instagram\Api\Feed
      */
      public $feed;

    /*

    • @var \phpinstagram\Instagram\Api\Auth
      */
      public $auth;

    public function __construct() {
    $this->feed = new \phpinstagram\Instagram\Api\Feed();
    $this->feed->setInstagram($this);
    $this->auth = new \phpinstagram\Instagram\Api\Auth();
    $this->auth->setInstagram($this);
    $this->_communication = new \phpinstagram\Instagram\Client\Communication();
    }

    public function addCommand(\phpinstagram\Instagram\Command\ICommand $cmd) {
    $this->_commands[] = $cmd;
    }

    public function run() {
    $executed = array();
    //$cookieJar = null;
    foreach ($this->_commands as $utcmd) {
    if ($utcmd instanceof \phpinstagram\Instagram\Command\ICommand) {
    /*
    * @var \phpinstagram\Instagram\Command\ICommand
    */
    $cmd = $utcmd;

            //if (!is_null($cookieJar))
            //  $this-&gt;_communication-&gt;getClient()-&gt;setCookieJar($cookieJar);
    
            foreach ($cmd-&gt;dependsOn() as $dependency) {
                foreach ($executed as $previous) {
                    if (get_class($previous) == '\Instagram\Command\\' . $dependency) {
                        break 2;
                    }
                }
                throw new \phpinstagram\Instagram\Command\DependencyException(
                    'Command ' . get_class($cmd) . " depends on $dependency but it never was executed!\n\n"
                );
            }
            $cmd-&gt;setCommunication($this-&gt;_communication);
    
            $cmd-&gt;validate();
    
            //echo get_class($cmd)." is valid. executing...\n\n";
            $cmd-&gt;exec();
    
            $executed[] = $cmd;
    
            // reset parameters
            $this-&gt;_communication-&gt;getClient()-&gt;resetParameters();
            //$cookieJar = $this-&gt;_communication-&gt;getClient()-&gt;getCookieJar();
        }
    }
    
    // reset commands
    $this-&gt;_commands = array();
    

    }



  • It's decided that the answer can be seen here: https://stackoverflow.com/questions/34184030/fatal-error-namespace-declaration-statement-has-to-be-the-very-first-statement




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2