php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64774 reassign of class's constant
Submitted: 2013-05-03 16:29 UTC Modified: 2013-05-03 16:41 UTC
From: ghanbari dot daniel at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.3.24 OS: ubuntu12.1
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: ghanbari dot daniel at gmail dot com
New email:
PHP Version: OS:

 

 [2013-05-03 16:29 UTC] ghanbari dot daniel at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/language.oop5.constants
---

why anyone can override constant of class?
in c++, i can assign const value only in construct method of class

Test script:
---------------
<?php

class test{
	const NAME = 100;
	public function ech(){
		$this->NAME = 300;
		$this->echt();
	}
	public function echt(){
		$this->NAME = 200;
		echo $this->NAME;
	}
}

$a=new test();
echo $a->ech();


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-05-03 16:41 UTC] nikic@php.net
$this->NAME is a property. You are looking for self::NAME or test::NAME.
 [2013-05-03 16:41 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue May 06 23:01:28 2025 UTC