# Dynamic class constants

- Thread: https://externals.io/message/13123
- Original archive: https://news-web.php.net/php.internals/13123
- Started by Marcus Boerger on 2004-10-03T17:23:35+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #13123 — Marcus Boerger — 2004-10-03T17:23:35+00:00

URL: https://externals.io/message/13123#13123

Hello internals,

  this patch allows to access class constants by objects.
If noone objects i'll commit it on tuesday.

Example:

class Test
{
    const Foo = 'Bar';
}

$obj = new Test;

var_dump($obj::Foo);

-- 
Best regards,
 Marcus

---

## #13161 — Andi Gutmans — 2004-10-05T01:03:20+00:00

URL: https://externals.io/message/13123#13161 · In reply to: #13123

Hi Marcus,

The patch looks fine. Before we commit I just want to make sure that we 
make sure we don't get bitten by this change sometime in the future.
In general, the idea is that writing $obj:: will be like doing class::. It 
can be useful in places such as Factories and other instances.
Although Marcus' patch is only for constants it would make sense to at some 
stage also support this notation for static properties, ala, $obj::$static_var.

What's important to note that this means that $obj:: would always evaluate 
to class:: and not to $obj_as_string::

Personally I think this makes sense but I'd like people to think about it.
So it'd mean that:
$obj::$static_var access static property $static_var of $obj's class
$obj::method() access static method method() of $obj's class
$obj::CONST accesses constant of $obj's class.

I haven't checked if this kind of implementation can be done and if there 
aren't any ambiguities but this is the general idea.

Feedback welcome.

Andi

At 07:23 PM 10/3/2004 +0200, Marcus Boerger wrote:
>Hello internals,
>
>   this patch allows to access class constants by objects.
>If noone objects i'll commit it on tuesday.
>
>Example:
>
>class Test
>{
>     const Foo = 'Bar';
>}
>
>$obj = new Test;
>
>var_dump($obj::Foo);
>
>--
>Best regards,
>  Marcus
