[nycphp-talk] define variables versus assigned variables
webmaster at vbplusme.com
webmaster at vbplusme.com
Sun Jan 3 00:52:44 EST 2010
Hello Konstantin,
Sunday, January 3, 2010, 1:22:50 PM, you wrote:
> 1. Your defined constants should be all CAPITALIZED.
> 2. I ran some tests earlier last year (2009) for this and found the following:
> - using class constants (and accessing it via
> ClassName::ConstantName) was about 30x faster than using define().
> - there were about 1000 constants used (it's a pretty big and
> configurable app).
> - the tests were run using ab (with the top 10% and bottom 10%
> edge results thrown out)
> - the tests were run with apc and without apc.
> Will it make or break your app when it's under stress? Definitely not.
> Konstantin
> On Sun, Jan 3, 2010 at 12:02 AM, <webmaster at vbplusme.com> wrote:
>> Hello ,
>>
>> Happy New Year to all,
>>
>>
>> I have two statements to make a database connection. One of them
>> using define statement variables to parse the information to the
>> function to connect to the database, i.e.
>>
>> open_connect(db_user, db_pass, db_name, db_host = 'localhost', $show_error=1)
>>
>> The second example uses assigned variables, for example,
>>
>> open_connect($db_user, $db_pass, $db_name, $db_host = 'localhost', $show_error=1)
>>
>> Seems to me that both of these techniques do the same thing so I was
>> wondering why one would be any advantage over the other, though I
>> just read that the define variables take twice as long to process
>> under some conditions. Can some one explain which technique is the
>> preferred method or whether or not any compelling reason exist for
>> using one over the other?
>>
>> Thanks in advanced for any comments.
>>
>>
>> --
>> Best regards,
>> Webmaster mailto:webmaster at vbplusme.com
>>
>> _______________________________________________
>> New York PHP Users Group Community Talk Mailing List
>> http://lists.nyphp.org/mailman/listinfo/talk
>>
>> http://www.nyphp.org/Show-Participation
>>
> _______________________________________________
> New York PHP Users Group Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
> http://www.nyphp.org/Show-Participation
> __________ Information from ESET NOD32 Antivirus, version of virus
> signature database 4738 (20100102) __________
> The message was checked by ESET NOD32 Antivirus.
> http://www.eset.com
Thanks for the update. My example here is flawed, the constants in my
sources are indeed all in upper case.
Are you suggesting that the username, password and datbase name all be
class constants and hard coded in the class definition? Sorry if this
is a dumb question, I am trying to get my head around PHP OOP and am
struggling a bit with the concepts. I am working with a database class
that I got from phpclasses.org to try to understand how things work.
--
Best regards,
Webmaster mailto:webmaster at vbplusme.com
More information about the talk
mailing list