PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > alt.php > Why do constants have quotes around when defined and class quoteshave no quotes??
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Why do constants have quotes around when defined and class quoteshave no quotes??

Réponse
 
LinkBack Outils de la discussion
Vieux 11/12/2007, 14h00   #1
adam.timberlake@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Why do constants have quotes around when defined and class quoteshave no quotes??

This is a really basic question for all you people out there who know
PHP. This is not a problem but just something I'm confused about. I
was reading the article below and wondered why are normal constants
set with quotes around them, while "class constants" (those little
things I learned yesterday from the article) don't have to have quotes
around the constants when you define them? It seems really weird to me
why PHP would do it this way??

Constants: http://www.talkphp.com/showthread.php?t=1151

Could someome please explain to me the reasons why there are 2 ways to
define them - one via a function, and one via, what is it? A language
construct? I don't know. The latter having no quotes around to
define!! Really weird.
  Réponse avec citation
Vieux 11/12/2007, 15h36   #2
Steve
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Why do constants have quotes around when defined and class quotes have no quotes??


<adam.timberlake@gmail.com> wrote in message
news:f2e552b9-4d03-4a2c-8137-acf51a7e3447@l1g2000hsa.googlegroups.com...
> This is a really basic question for all you people out there who know
> PHP. This is not a problem but just something I'm confused about. I
> was reading the article below and wondered why are normal constants
> set with quotes around them, while "class constants" (those little
> things I learned yesterday from the article) don't have to have quotes
> around the constants when you define them? It seems really weird to me
> why PHP would do it this way??
>
> Constants: http://www.talkphp.com/showthread.php?t=1151
>
> Could someome please explain to me the reasons why there are 2 ways to
> define them - one via a function, and one via, what is it? A language
> construct? I don't know. The latter having no quotes around to
> define!! Really weird.


not weird at all. in php < 5, there's only one way to define a constant:

define('A_CONSTANT', 666);

in php 5+, define() is kept not only for backward compatability but for
other reasons as well. the difference is, with newer versions of php, we've
picked up a new language construct, const. so now, you can define a constant
just at you did class vars in php (all versions)...

class foo
{
const A_CONSTANT = 666;
var $someVar = 777;
}

it's simply a matter of a language construct change.


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 10h03.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10548 seconds with 10 queries