# Constant Scope PHP5

- Thread: https://externals.io/message/4127
- Original archive: https://news-web.php.net/php.internals/4127
- Started by Arjen Brouwer on 2003-08-22T11:35:01+00:00
- Messages: 8
- 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

---

## #4127 — Arjen Brouwer — 2003-08-22T11:35:01+00:00

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

Should'nt this work? Currently it reports an error about a undefined constant.

<?
class Test {
    const FOO = 100;
    var $bar = FOO;
}

$Test = new Test;
echo $Test->bar;
?>

Ciao,
Arjen

---

## #4131 — Cristiano Duarte — 2003-08-22T19:34:58+00:00

URL: https://externals.io/message/4127#4131 · In reply to: #4127

"Arjen Brouwer" <arjenjb@quicknet.nl> escreveu na mensagem
news:001b01c368a1$775b2070$6402a8c0@sleepert...
> Should'nt this work? Currently it reports an error about a undefined
constant.
>
> <?
> class Test {
>     const FOO = 100;
>     var $bar = FOO;
> }
>
> $Test = new Test;
> echo $Test->bar;
> ?>
>
> Ciao,
> Arjen
>

IMHO it should.

Cristiano Duarte.

---

## #4138 — Zeev Suraski — 2003-08-22T22:30:06+00:00

URL: https://externals.io/message/4127#4138 · In reply to: #4127

At 14:35 22/08/2003, Arjen Brouwer wrote:
>Should'nt this work? Currently it reports an error about a undefined constant.
>
><?
>class Test {
>     const FOO = 100;
>     var $bar = FOO;

Should be var $bar = Test::FOO (or self::FOO, even though it appears not to 
work right now) - there's no implicit class/object dereference of any kind 
in PHP.

Zeev

---

## #4140 — DvDmanDT — 2003-08-23T04:03:06+00:00

URL: https://externals.io/message/4127#4140 · In reply to: #4138

Wait a sec... When did const become a keyword? And since when can you
initialize variables from outside a constructor/function?

Sorry to bother..

-- 
// DvDmanDT
MSN: dvdmandt@hotmail.com
Mail: dvdmandt@telia.com
"Zeev Suraski" <zeev@zend.com> skrev i meddelandet
news:5.1.0.14.2.20030823012845.0576f768@localhost...
> At 14:35 22/08/2003, Arjen Brouwer wrote:
> > […]
constant.
> > […]
>
> Should be var $bar = Test::FOO (or self::FOO, even though it appears not
to
> work right now) - there's no implicit class/object dereference of any kind
> in PHP.
>
> Zeev

---

## #4142 — Zeev Suraski — 2003-08-23T14:10:08+00:00

URL: https://externals.io/message/4127#4142 · In reply to: #4138

At 07:03 23/08/2003, DvDmanDT wrote:
>Wait a sec... When did const become a keyword?

In PHP 5.0.

>And since when can you
>initialize variables from outside a constructor/function?

Since PHP 3.0 :)

Zeev

---

## #4143 — l0t3k — 2003-08-23T17:40:57+00:00

URL: https://externals.io/message/4127#4143 · In reply to: #4142

Zeev,
   speaking of const, i have a feature request. why not accept "const" in
the global context and create a compile-time global constant ?
e.g.

    const FOO = 1 ;
    const BAR = 2;

    class Barbara {
        const Barbara::BUSH = FOO;
    };

i'd much prefer this as an alternative to the runtime `define()`.

l0t3k


"Zeev Suraski" <zeev@zend.com> wrote in message
news:5.1.0.14.2.20030823170950.05b14e30@localhost...
> At 07:03 23/08/2003, DvDmanDT wrote:
> > […]
>
> In PHP 5.0.
>
> > […]
>
> Since PHP 3.0 :)
>
> Zeev

---

## #4145 — Zeev Suraski — 2003-08-23T18:19:55+00:00

URL: https://externals.io/message/4127#4145 · In reply to: #4142

At 20:40 23/08/2003, l0t3k wrote:
>Zeev,
>    speaking of const, i have a feature request. why not accept "const" in
>the global context and create a compile-time global constant ?
>e.g.
>
>     const FOO = 1 ;
>     const BAR = 2;
>
>     class Barbara {
>         const Barbara::BUSH = FOO;
>     };
>
>i'd much prefer this as an alternative to the runtime `define()`.

It's going to be runtime either way, because you could do if (...) { const 
FOO = 1; } else  {const FOO = 2 }.  Not sure if we want it as syntactic 
sugar for `define()` or not.

Zeev

---

## #4154 — Curt Zirzow — 2003-08-23T22:14:02+00:00

URL: https://externals.io/message/4127#4154 · In reply to: #4145

* Thus wrote Zeev Suraski (zeev@zend.com):
> At 20:40 23/08/2003, l0t3k wrote:
> > […]
> 
> It's going to be runtime either way, because you could do if (...) { const 
> FOO = 1; } else  {const FOO = 2 }.  Not sure if we want it as syntactic 
> sugar for `define()` or not.

This would be nice! Id like to add perhaps, but not sure how hard
it would be, to make this constant (aliased define) unchangeable
through out the life time of the script.

Curt
-- 
"I used to think I was indecisive, but now I'm not so sure."
