Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8225493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:26:11+00:00 2026-06-07T15:26:11+00:00

I have the following code that I’m using in a small frame work I’ve

  • 0

I have the following code that I’m using in a small frame work I’ve put together. My framework didn’t originally use Namespaces, but since two class names collide in this project I figured it would be a good time to try this out. The following error is thrown when the script is executed:

[Wed May 02 15:04:33 2012] [error] [client 127.0.0.1] PHP Parse error:  syntax error, unexpected T_VARIABLE, expecting T_STRING in /home/marco/Projects/stackgaming.com/app/server.php on line 17

Here is the following code snippets relevant to the error:

app/server.php

if( !defined('IN_APP') ) { die('THESE ARE NOT THE DROIDS YOU ARE LOOKING FOR'); }

require_once('model/Server.php');

\Model\Server::$save_path = APPLICATION_ROOT . 'servers';

class Server extends App
{
    public static function init($server_id)
    {
        $server_data = \Model\Server::get($server_id);
        $game = $server_data['interface'];
        require_once('model/' . $game . '.php');

        $query_data = \Model\$game::query($server_data['host'], $server_data['query_port']);

        var_dump($server_data);
        var_dump($query_data);

        //static::$View->display('user_main.tpl');
    }
}

This is the model/Minecraft.php file, which is what $game resolves to.

<?php

namespace Model;

class MinecraftException extends \Exception
{
    // Exception thrown by Minecraft classes
}

class Minecraft
{
    public static function query( $host, $port = 25565, $timeout = 3 )
    {
        $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

        socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, array('sec' => $timeout, 'usec' => 0));

        if( $socket === false || @socket_connect($socket, $host, (int)$port) === false )
        {
            return false;
        }

        socket_send($socket, "\xFE", 1, 0);
        $len = socket_recv($socket, $data, 256, 0);
        socket_close($socket);

        if( $len < 4 || $data[ 0 ] != "\xFF" )
        {
            return false;
        }

        $data = substr($data, 3);
        $data = iconv('UTF-16BE', 'UTF-8', $data);
        $data = explode("\xA7", $data);

        return array
        (
            'hostname'   => substr($data[0], 0, -1),
            'total_players'    => isset($data[1]) ? intval($data[1]) : 0,
            'max_players' => isset($data[2]) ? intval($data[2]) : 0
        );
    }
}

If I remove the namespace from Minecraft class it works fine, but if I’m going to use namespaces shouldn’t I go all the way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T15:26:12+00:00Added an answer on June 7, 2026 at 3:26 pm

    I found this question much sooner than I found a resolution to it. For everyone’s benefit, here is a helpful link to resolving the issue at hand: Variable functions with namespaces in PHP

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following code that does not work due to a being a value
I have following code that does not work: I never get to goToFoodDetail .
I have following code snippet that i use to compile class at the run
I have the following code that I have been using to Set properties in
I have the following code that I use to compute the distance between two
I'm trying to use Entity Framework to query database and I have following code
I have the following code that I use to resize some images on my
I have following code that I'm trying to test using NUnit and Rhino mocks.
I have the following code that uses 'paste' and AWK script inside Perl. use
I have the following code that extracts urls from a given page using jsoup.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.