php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54366 Constants in and among classes, in simulating structs -and- static variables
Submitted: 2011-03-24 13:05 UTC Modified: 2013-02-18 00:34 UTC
From: cnick at titancrest dot com Assigned:
Status: No Feedback Package: *General Issues
PHP Version: 5.3.6 OS: Windows 7 Ultimate 32bit
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
22 - 18 = ?
Subscribe to this entry?

 
 [2011-03-24 13:05 UTC] cnick at titancrest dot com
Description:
------------
---
From manual page: http://www.php.net/language.oop5.constants
---

//Simulate Struct
class VolumeWeight
{
    const GRAMS = 'gm';
    const MILILITRE = 'ml';    
}

- or -

class VolumeWeight
{
    public static $GRAMS = 'gm';
    public static $MILILITRE = 'ml';    
}

Then have another (extended) struct

class WaterBottle
{
    public static $ITEM_ID = 1324;
    public static $ITEM_COST = 0.23;

    public static $UNIT = VolumeWeight::$MILILITRE; //Yields an error

}

- BUT -

class WaterBottle
{
    public static $ITEM_ID = 1324;
    public static $ITEM_COST = 0.23;

    public static $UNIT = VolumeWeight::MILILITRE; //Works (from constant class)

}

- AND -

class WaterBottle
{
    const ITEM_ID = 1324;
    const ITEM_COST = 0.23;

    const UNIT = VolumeWeight::MILILITRE; //Error (from constant class)
}

How weird is that? Anything I can do?


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-03-24 23:01 UTC] felipe@php.net
-Status: Open +Status: Feedback
 [2011-03-24 23:01 UTC] felipe@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.

Simplify the report. :)
 [2013-02-18 00:34 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 10:01:29 2024 UTC