php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #32523 wrong error message assigning to $this
Submitted: 2005-04-01 00:09 UTC Modified: 2006-04-03 13:48 UTC
From: info at rhalff dot com Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 5CVS-2005-03-31 (dev) OS: debian
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: info at rhalff dot com
New email:
PHP Version: OS:

 

 [2005-04-01 00:09 UTC] info at rhalff dot com
Description:
------------
The error message when assigning to $this is kinda misleading. It seems to default to cannot re-assign $this even when not in object context.

Maybe it could be defaulted to some kind of error message stating $this is a reserved variable name which can only be used in object context.





Reproduce code:
---------------
<?php $this = ''; ?>

Expected result:
----------------
something else then cannot re-assign $this...

Actual result:
--------------
PHP Fatal error:  Cannot re-assign $this in.....

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-03 13:48 UTC] tony2001@php.net
$this is reserved.
Imagine that you're include'ing this code in a class where $this exists. We have to prevent $this overwriting in this case.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 12:01:31 2025 UTC