Re: Declare Function - Unpost me!

From: Date: Tue, 15 Apr 2003 17:31:52 +0000
Subject: Re: Declare Function - Unpost me!
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-143990@lists.php.net to get a copy of this message
In my previous post, I was wrong in saying constants can't be used in expressions. Thanks to the members of this list for setting me straight (and without any hint of a flame!). (By way of shifting the blame :) the book I used to learn PHP, Wrox's "Professional PHP4", compares PHP's constants to C pre-processor #defines and gives a poor example of their use. I then jumped to my own erroneous conclusions. After further study, the only limitation to constants I see is they can't be used for substitution in strings since they don't have the distinguishing $ prefix. I apologize for the disinformation. --Frappy On Tuesday 15 April 2003 12:42 am, Frappy John wrote: > Burhan: > > You asked a very good question. I've wondered if there's > a good use for PHP's declared constants too. And I hope > someone who understands them replies with a good > explanation. > > I see where one reply so far identified them as a > "constant." That's PHP's term. But they aren't really > constants in the traditional sense since you can't use > them in expressions. > > I see where another reply called them "execution > parameters," (which to my mind is just a fancy term for > "constant"). > > They remind me more of compile-time parameters. (Actually > they remind me of assembly-time parameters.) But since > PHP isn't compiled (or is compiled transparently at > execution time), I suppose "execution parameters" is as > good a term for them as any. > > I've been able to spin some pretty sophisticated systems > without ever using these "constants". If I need a > constant, I define a variable using a name in all-caps > (so I'll remember not to change it). That way I can use > it in regular conditions and expressions. > > It's possible their proper use could lead to efficiencies > if they can be used to avoid the JIT compilation of large > blocks of unused code (i.e. conditional compilation). But > I don't know that that's the case. > > Does anyone know? > > --Frappy > > On Monday 14 April 2003 06:07 pm, lists@linuxgroup.net > > wrote: > > I haven't done anything with declare before, so could > > you give me a brief explanation of what "execution > > parameters" are. Or, when it would be better to use > > declare. Thanks! > > > > Burhan Khalid <phplist@meidomus.com> wrote: > > > Hello lists, > > > > > > Monday, April 14, 2003, 4:48:24 PM, you wrote: > > > > > > lln> Whats the difference between > > > > > > > > > lln> $var = "blah"; > > > > > > This declares a variable. > > > > > > lln> declare('var', 'blah'); > > > > > > This defines execution parameters for a block of > > > code. Two very different things. > > > > > > -- > > > Burhan Khalid > > > phplist[at]meidomus[dot]com > > > > > > Please add reply-to: header with > > > the list's email address for proper > > > correspondence. > > > > _______________________________________________________ > >__ __ This mail sent using V-webmail - > > http://www.v-webmail.co.uk

« previous php.general (#143990) next »