Edit report at https://bugs.php.net/bug.php?id=65305&edit=1

 ID:                 65305
 Comment by:         ni...@php.net
 Reported by:        ryan at skidmore dot pro
 Summary:            $this keyword is treated like a variable under
                     certain circumstances
 Status:             Not a bug
 Type:               Bug
 Package:            Class/Object related
 Operating System:   Linux/Ubuntu
 PHP Version:        5.4.17
 Block user comment: N
 Private report:     N

 New Comment:

Why would it be logical? PHP treats all variables case-sensitively, so it's not 
really obvious to me why $this should be any different in this regard.


Previous Comments:
------------------------------------------------------------------------
[2013-07-21 15:03:08] ryan at skidmore dot pro

Surely it would be logical to treat $This exactly the same as $this though?

------------------------------------------------------------------------
[2013-07-21 14:54:36] ni...@php.net

$this *is* a variable and variables in PHP are case-sensitive. Thus your code 
makes a method call on null, which results in a fatal error.

------------------------------------------------------------------------
[2013-07-21 14:47:47] ryan at skidmore dot pro

Description:
------------
When capitalising the first letter of the $this keyword to $This and then 
assigning it to a variable (with appropiate class structures) like this: 
"$Variable = $This->Class1->Function1();" causes PHP to throw an error and not 
display the page, when $This is changed to $this, it works fine.

Test script:
---------------
This test script is fit into two parts, for two separate files.

** UNCOMMENT THE LINES TO REPRODUCE PROBLEM

** FILE 1 ** (The file to be run)

Class Class1
{
        
        Public $Class2Inst;
        
        Public function __construct()
        {
                
                include("phpbug2.php"); // ******* Change this to the path of 
the other file.
                
                $this->Class2Inst = new Class2;
                
                //$Variable1 = $This->Class2Inst->Func1(); // This produces 
error
                
                //$Variable2 = $this->Class2Inst->Func1(); // This does not 
produce error
                
                echo $Variable2;
                
        }
        
}

$Class1Inst = new Class1;


** FILE 2 ** The file that gets included

Class Class2
{
        
        Public function Func1()
        {
                
                return "Function 1 is being run";
                
        }
        
}


Expected result:
----------------
The expected result is that Func1 within the Class2 class is run.

Actual result:
--------------
The $This keyword is treated like a variable, instead of like a keyword.


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=65305&edit=1

Reply via email to