define constants in class

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
allelopath
Forum Commoner
Posts: 34
Joined: Tue Mar 16, 2004 5:21 am

define constants in class

Post by allelopath »

This is ok:

<?php
define ("HOME_BTN", "Home");
class Menu
{
}
?>

This is not
<?php
class Menu
{
define ("HOME_BTN", "Home");
}
?>

It won't let me define a constant class member.
(gives a parse error on the define line)
Why?
User avatar
EvilWalrus
Site Admin
Posts: 209
Joined: Thu Apr 18, 2002 3:21 pm
Location: Springmont, PA USA

Post by EvilWalrus »

Class constants are available in PHP5, but not in PHP4...

Code: Select all

<?php

class foo
{
    public const bar = 'baz';

    ...
}

?>
allelopath
Forum Commoner
Posts: 34
Joined: Tue Mar 16, 2004 5:21 am

Post by allelopath »

darn, it looks like there's many Java like things in PHP5,
but i cannot upgrade
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

PHP 5 Release Candidate 1 Released! [18-Mar-2004]
Post Reply