0

I would like to use a simple variable that makes a role in the class... however, this is not working.

$GLOBALS['world'] = "Isara";

class Character{
    var $name;
    var $status;
    static $content;
    function __construct($name){
        $this->name=$name;
        $this->getCharInfo();
    }

    private function getCharInfo(){
        if(empty(self::$content)){
            self::$content = file_get_contents("http://www.tibia.com/community/?subtopic=worlds&world=$GLOBALS['world']",0);

1 Answer 1

3

Using $GLOBALS[...] to access global variables is correct. However, when embedding array accessors in strings, you need to wrap the variable in brackets.

So, instead of

file_get_contents("... $GLOBALS['world']");

you could use one of the following:

file_get_contents("... {$GLOBALS['world']}");
file_get_contents("... " . $GLOBALS['world']);

or:

global $world;
file_get_contents("... $world");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.