Cynosure.X International

:

Add Comment | Related Links | TrackBack
Related Content

Pitfall of Defining Constants

The PHP define statement is really handy. I've used it to define all kind of constants. But recently I stumbled across a pitfall when I defined a constant name two different ways different if clauses. In the true clause, I defined it one way, while defining it another way in the false clause. The constant never changes. Two things I learned from this exercise.

  • Once a constant is defined, it can't be changed with another define statement.
  • All constants come into play as soon as the script is run; it doesn't matter if you put it in a scope bracket.

Knowing these constraints, I started developing my software more carefully, using scoped class variables, rather than using constants all the time. You might end up stepping on yourself quite often if you keep defining global constants.

Chieh Cheng
Wed, 23 Apr 2008 16:24:48 +0000

Add Comment | Related Links | TrackBack
Related Content

Did your message disappear? Read the Forums FAQ.

Add Comment

Spam Control | * indicates required field
Your Name: *
E-mail:
Remember Me!
Comment: *
File attachment is optional. Please do not attach a file to your submission unless it is relevent.
Attach File:
(20 MB Max)
Spam Protection: * Answer of 5 - 9?
Click button only once, please!

TrackBack

Send Ping | TrackBack URL | Spam Control

No TrackBacks yet. TrackBack can be used to link this thread to your weblog, or link your weblog to this thread. In addition, TrackBack can be used as a form of remote commenting. Rather than posting the comment directly on this thread, you can posts it on your own weblog. Then have your weblog sends a TrackBack ping to the TrackBack URL, so that your post would show up here.

Messages, files, and images copyright by respective owners.

Products | Services
Forums | Latest | RSS
Library | Search | Wiki
Help | Licenses

Login | Register

19 Users Online

Hacking Digital Cameras
Fun for Photographers


Amazon Associate

Copyright © 1996 - 2017. All Rights Reserved.