php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36411 name of parameter in static method
Submitted: 2006-02-16 09:39 UTC Modified: 2006-02-16 09:41 UTC
From: Sm0ke999 at yandex dot ru Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.1.2 OS: Win xp
Private report: No CVE-ID: None
 [2006-02-16 09:39 UTC] Sm0ke999 at yandex dot ru
Description:
------------
Why in "static method" name of "parameter" can not be "$this" ?

Reproduce code:
---------------
<?php
header("Content-Type: text/plain; charset=koi8-r");

class Base
{
	public $x= 'x', $y= 'y';
	
	public static function fnTest($this)
	{
		echo __CLASS__,'::',__FUNCTION__,"()\t",get_class($this),"\n";
		list($this->x, $this->y)= array($this->y, $this->x);
		print_r($this);
	}
}

$o= new Base;
Base::fnTest($o);
?>

Expected result:
----------------
Base::fnTest()Base
Base Object
(
    [x] => y
    [y] => x
)

Actual result:
--------------
[Thu Feb 16 11:31:32 2006] [error] [client 192.168.0.250] PHP Fatal error:  Using $this when not in object context in D:\\dev\\Site\\test.htm on line 11

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-02-16 09:41 UTC] derick@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

Because "$this" has a special meaning in PHP.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jul 01 13:01:33 2024 UTC