Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> class::const, Definiowanie stałej w klasie
ennics
post
Post #1





Grupa: Zarejestrowani
Postów: 312
Pomógł: 0
Dołączył: 29.12.2004

Ostrzeżenie: (0%)
-----


cześć, mam problem ze zdefinowaniem stałej w klasie (PHP5.0.1):

  1. <?php
  2.  
  3. if (PHP_OS == 'Linux') {
  4.     $dirname = dirname(__FILE__) . DIRECTORY_SEPARATOR;
  5. } else {
  6.     $dirname = str_replace("", "/", dirname(__FILE__) . DIRECTORY_SEPARATOR);
  7. }
  8.  
  9. define('SRCDIR', $dirname);
  10. define('LIBDIR', SRCDIR . 'LIB/');
  11.  
  12. class conf {
  13.     const SOMEDIR = SRCDIR . 'd';
  14.     const SOMECNS = SRCDIR;
  15. }
  16. print conf::SOMEDIR;
  17. print conf::SOMECNS;
  18.  
  19. ?>

w rezultacie print conf::SOMEDIR daje:
Parse error: parse error, unexpected '.', expecting ',' or ';' in /var/www/test/5/2.0/conf.inc.php on line 42
print conf::SOMECNS działa dobrze:
zwraca /var/www/test/5/2.0/
dlaczego nie mogę nic dowiązać do stałej za pomocą operatora kropki ?

Ten post edytował ennics 24.11.2005, 10:25:57


--------------------
Go to the top of the page
+Quote Post
czachor
post
Post #2





Grupa: Zarejestrowani
Postów: 897
Pomógł: 40
Dołączył: 16.12.2003
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


Bo to jest stała smile.gif


--------------------
how many SEO experts does it take to change a light bulb,lightbulb,light,bulb,lamp,lighting,switch,sex,xxx
5-Reasons-why-you-should-NEVER-fix-a-computer-for-free
Go to the top of the page
+Quote Post
ennics
post
Post #3





Grupa: Zarejestrowani
Postów: 312
Pomógł: 0
Dołączył: 29.12.2004

Ostrzeżenie: (0%)
-----


hmm no ok winksmiley.jpg, ale wcześniej wykonałem podobną operację przy definiowaniu 'LIBDIR'
  1. <?php
  2.  
  3. define('SRCDIR', $dirname);
  4. define('LIBDIR', SRCDIR . 'LIB/'); // <- dowiązuje do stałej.
  5.  
  6. ?>


--------------------
Go to the top of the page
+Quote Post
nospor
post
Post #4





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




moze dlatego:
Cytat
"The value must be a constant expression, not (for example) a variable,
a class member, result of a mathematical operation or a function call."

define a const chyba mają prawo sie różnic?


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 19.08.2025 - 19:50