"const" in PHP
| From: | BENARD Jean-philippe | Date: | Thu, 16 Oct 2003 11:12:43 +0000 |
| Subject: | "const" in PHP | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-166282@lists.php.net to get a copy of this message | ||
Hi,
With the ArcaAttributes class definition (see below) I've an arror
when trying to use one of the constants of this class as this :
echo ArcaAttributes::ATT_EMPLOYEENUMBER;
Parse error: parse error, expecting `'('' in
/dtpdev01/dtp/racine-web/arca_test/test.php on line 117
It seams waiting only functions when using "::".
Could someone help me ? How to define constant in a cless without the
"define()" function ? (I don't want to use the define function because it
makes the constant defined everywhere).
Many thanks in advance !
>>>
class ArcaAttributes {
/**
* Liste des attributs à retourner
* @var array
*/
var $attributes = array();
var $set = false;
const ATT_EMPLOYEENUMBER = 'uid';
const ATT_CN = 'cn';
const ATT_MAIL = 'mail';
const ATT_POSTALADDRESS = 'postofficebox';
const ATT_TELEPHONENUMBER = 'telephonenumber';
const ATT_DEFAULT_PERSON_ATTRIBUTES = array(
ArcaAttributes::ATT_EMPLOYEENUMBER,
ArcaAttributes::ATT_CN,
ArcaAttributes::ATT_MAIL,
ArcaAttributes::ATT_POSTALADDRESS,
ArcaAttributes::ATT_TELEPHONENUMBER
);
function ArcaAttributes($clearList = false) {
if ($clearList)
$this->attributes = array();
else
$this->setDefaultAttributes();
}
function addAttribute($attrib) {
array_push($this->attributes, $attrib);
}
function clearAttributes($clearList = false) {
if ($clearList) {
$this->set = false;
$this->attributes = array();
}
else
$this->setDefaultAttributes();
}
function setDefaultAttributes() {
$this->set = true;
$this->attributes =
ArcaAttributes::ATT_DEFAULT_PERSON_ATTRIBUTES;
}
function is_set() {
if ($this->set === true)
return true;
else
return false;
}
}
<<<
(o_ BENARD Jean-Philippe - Consultant STERIA Infogérance
(o_ (o_ //\ RENAULT DTSI/ODPS/R@D * ALO * API : MLB 02C 1 14
(/)_ (\)_ V_/_ 2 Av du vieil étang * 78181 MONTIGNY-LE-BRETONNEUX
Tél : +33 1-30-03-47-83 * Fax : +33 1-30-03-42-10