$this->document_root = $_SERVER['DOCUMENT_ROOT']; broken ?

I have been using ZendStudio for several years, and am trying to switch over to phpstorm

There are a lot of things I use the following for :

$this->document_root   = $_SERVER['DOCUMENT_ROOT'];

or

$document_root  = $_SERVER['DOCUMENT_ROOT'];


but the debugger allways shows the value of : $this->document_root = ""

which basically shutsdown any further processing for me. I searched on the forum and found a number of messages associated with include($_SERVER['DOCUMENT_ROOT']... causing a problem, but I am merely trying to assign the value of $_SERVER['DOCUMENT_ROOT'] to other variables for further processing.

This should work ?

Bill Hernandez
Plano, Texas

3 comments
Comment actions Permalink

Hi there,

Can you describe your problem little bit in details, please?

This seems to be work fine for me (Windows 7 x64 SP1; IIS 7.5; PHP 5.4.13 nts via FastCGI; xdebug 2.2.1); PhpStorm v6

screen01.png

0
Comment actions Permalink

Andriy,

I have multiple virtual hosts on my development machine, and was trying to get the first one setup.

I had not specified the absolute path on the server, although this may not be relevant, because on the new small project (which you sent me) listed below I did not specify an absolute path, and everything seemed to work fine. ?

I think the problem was related to an incorrect mapping (maybe), but I had also incorrectly selected "PHP Script" instead of "PHP Web Application", once I deleted the "PHP Script" and created a  "PHP Web Application", this cleared up the problem, and $a->document_root = $_SERVER['DOCUMENT_ROOT']; works fine.

From your suggestion, I tried :


<?php

class SomeClass
{
    public $document_root = "";

    public function doIt()
    {
        echo $this->document_root;
    }
}

$show_class_demo = true;

if($show_class_demo)
{
    $a = new SomeClass();
    $a->document_root = $_SERVER['DOCUMENT_ROOT'];
    $a->doIt();
}


Everything is working correctly. Over the next few days I am going to try to get phpstorm working with my setup, so hopefully I will be able to transition from ZendStudio,

Thank you very much for your prompt reply.

Bill Hernandez
Plano, Texas

0
Comment actions Permalink
but I had also incorrectly selected "PHP Script" instead of "PHP Web Application", once I deleted the "PHP Script" and created a  "PHP Web Application", this cleared up the problem, and $a->document_root = $_SERVER['DOCUMENT_ROOT']; works fine.

Most likely that was the cause: "PHP Script" is for executing script in CLI environment where $_SERVER['DOCUMENT_ROOT'] will be empty indeed.

0

Please sign in to leave a comment.