Re: [PHP] Constants in strings

2011-07-08 Thread Pete Ford

On 06/07/11 17:33, Robert Williams wrote:

Where I've made most use of heredocs is when I want to do nothing but define a 
bunch of
long strings in one file.


I find the most useful thing about heredocs is that they don't care about 
quotation marks, so I often use them for SQL statements where I might have a 
mixture of ' and "


eg.

$sql =<

Re: [PHP] Constants in strings

2011-07-06 Thread Robert Cummings

On 11-07-06 02:59 PM, Jim Giner wrote:

I LOVE the heredocs tool.  I only learned about it a couple of months ago -
what a find!  It makes generating my html for my web pages so much
easier and allows me to include my php vars within the html with much less
confusion and simplifies the intermixing of html and php vars - no more
single quote, double quote and dot stuff in an html tag.
Sure you have to put the closing tag in column 1 - a mere blip against the
pros.


With respect to putting the closing tag in column 1... I've found the 
following to be fairly unobtrusive:




Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Constants in strings

2011-07-06 Thread Jim Giner
I LOVE the heredocs tool.  I only learned about it a couple of months ago - 
what a find!  It makes generating my html for my web pages so much 
easier and allows me to include my php vars within the html with much less 
confusion and simplifies the intermixing of html and php vars - no more 
single quote, double quote and dot stuff in an html tag.
Sure you have to put the closing tag in column 1 - a mere blip against the 
pros. 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Constants in strings

2011-07-06 Thread Robert Williams
On 2011-07-6 08:09, "ad...@buskirkgraphics.com"
 wrote:



>I use constants in my OOP and I never use the heredoc syntax. Now I am
>fearing that I have not taken advantage of something.
>My understanding of heredoc syntax as of 5.3 is just a string quoting
>right?
>Is there an advantage of using the heredoc syntax over single quoted or
>double quoted?

I don't believe that a heredoc will perform significantly differently than
a double-quoted string, as, from the parser's POV, they're essentially the
same thing once you get past the step of extracting the entire string from
the source. I've not verified this by reviewing the relevant source,
however, nor have I benchmarked it. But, I'm willing to bit that even if
there is a difference, it's so small that you're better off worrying about
which will lead to easier code maintenance than worrying about performance
(as is typically the case with such micro-optimization choices).

In my view, what's important is how you use them. In particular, a heredoc
can present a bit more cleanly when you're dealing with a large-ish chunk
of text, as in, say, an e-mail message template. The main downside is that
they will usually make a mess of code formatting, since the closing
delimiter must be against the left margin. For this reason, I tend to
prefer multi-line double-quoted strings over heredocs when I have
meaningful indentation, as in a function or class method. Where I've made
most use of heredocs is when I want to do nothing but define a bunch of
long strings in one file. For example, I might create a file to define a
set of related e-mail message templates:



Of course, this is arguably as clean:



With the latter, there is the catch that you end up with leading and
trailing line breaks, but those are easy enough to deal with, if desired.

As to the original topic of this thread, it's long annoyed me that there's
no easy way to use constants with interpolation. Since I find repeated
concatenation extremely ugly and prone to editing error (the same reason I
wouldn't use syntax any more complicated than {{foo}} even if it did
work), I end up taking the approach of defining a variable to use instead,
usually with a prefix to make clear that it's an understood constant
(e.g., $kUsername). And if I have to do this for one constant, I do it for
all related constants even if not needed, just for the sake of
consistency. This means that I frequently end up using variables where
constants would work just fine. With the prefix convention and a
disciplined team, this proves easily tenable, but it's not ideal.

-Bob


--
Robert E. Williams, Jr.
Associate Vice President of Software Development
Newtek Businesss Services, Inc. -- The Small Business Authority
http://www.thesba.com/


Notice: This communication, including attachments, may contain information that 
is confidential. It constitutes non-public information intended to be conveyed 
only to the designated recipient(s). If the reader or recipient of this 
communication is not the intended recipient, an employee or agent of the 
intended recipient who is responsible for delivering it to the intended 
recipient, or if you believe that you have received this communication in 
error, please notify the sender immediately by return e-mail and promptly 
delete this e-mail, including attachments without reading or saving them in any 
manner. The unauthorized use, dissemination, distribution, or reproduction of 
this e-mail, including attachments, is prohibited and may be unlawful. If you 
have received this email in error, please notify us immediately by e-mail or 
telephone and delete the e-mail and the attachments (if any).

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Constants in strings

2011-07-06 Thread admin
> -Original Message-
> From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk]
> Sent: Wednesday, July 06, 2011 10:49 AM
> To: ad...@buskirkgraphics.com; 'Dave Wilson'; php-general@lists.php.net
> Subject: RE: [PHP] Constants in strings
> 
> 
> 
> >
> >define('DIR_JAVA', '/js/');
> >
> >When you need to use the JavaScript directory you can do this.
> >
> >
> >There is no true need for the curly brackets to echo out the value of
> >the constant.
> >
> 
> Except for when you're using heredoc, much like in the OPs first
> post...
> 
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
> --
> Sent from my Android phone with K-9 Mail. Please excuse my brevity.


Ash,
I have a few questions.
I use constants in my OOP and I never use the heredoc syntax. Now I am fearing 
that I have not taken advantage of something.
My understanding of heredoc syntax as of 5.3 is just a string quoting right?
Is there an advantage of using the heredoc syntax over single quoted or double 
quoted?

Examples:

Echo 'your constant for the javascript path is '.DIR_JAVA;

Echo <<http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Constants in strings

2011-07-06 Thread Curtis Maurand



Yeah, that was my answer and I was rebuked for that.

ad...@buskirkgraphics.com wrote:
>> -Original
Message-
>>
From: Dave Wilson
[mailto:dai_bac...@hotmail.com]
>> Sent: Wednesday, July 06,
2011 10:11 AM
>> To: php-general@lists.php.net
>>
Subject: Re: [PHP] Constants in strings
>>
>> On
Wed, 06 Jul 2011 12:56:21 +0100, Stuart Dallas wrote:
>> >
My guess is that the preceding $ causes PHP to interpret the next
>> token
>> > "{XYZ}" as a variable or a
constant, but without that preceding $ it
>> has
>>
> no way to know you're trying to use a constant. As Curtis points
out,
>> > the only way to insert a constant into a string is
through
>> > concatenation.
>> >
>>
> -Stuart
>>
>> OK. I should have made myself
clearer - I was making an observation
>> with
>>
regards to constant parsing in strings rather than looking for advice.
>> My
>> bad.
>>
>> My third
example showed that "{${XYZ}}" would echo the value of the
>> variable called the value of XYZ:
>> > define ('XYZ','ABC');
>>
>>
$ABC="huh!";
>>
>> echo
"{${XYZ}}\n";
>> ?>
>> Output - huh!
>>
>> We could easily re-write the 'echo' line above to
be:
>> echo "{${constant('XYZ'}}\n";
>>
>> But my example shows that PHP *is* accessing the value of a
constant
>> without any jiggery-pokery or hacks (e.g.
http://www.php.net/manual/en/
>>
language.types.string.php#91628) as it is retrieving the value of ABC
>> from the XYZ constant and then looking for a variable of that
name.
>>
>> I admit that I'm no C coder but it may
be possible (note, the word
>> "may")
>>
that a change of code within the PHP source tree will allow us to use
>> something like echo "{{XYZ}}" to access the constant
value.
>>
>> Cheers
>>
>>
Dave
>>
>>
>> --
>> PHP
General Mailing List (http://www.php.net/)
>> To unsubscribe,
visit: http://www.php.net/unsub.php
> 
> 
> 
> define('DIR_JAVA', '/js/');
> 
> When you need to
use the JavaScript directory you can do this.
> 
> 
>
There is no true need for the curly brackets to echo out the value of
the
> constant.
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
>

> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
>


RE: [PHP] Constants in strings

2011-07-06 Thread Ashley Sheridan


>
>define('DIR_JAVA', '/js/');
>
>When you need to use the JavaScript directory you can do this.
>
>
>There is no true need for the curly brackets to echo out the value of
>the constant.
>

Except for when you're using heredoc, much like in the OPs first post...

Thanks,
Ash
http://www.ashleysheridan.co.uk
--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Constants in strings

2011-07-06 Thread admin
> -Original Message-
> From: Dave Wilson [mailto:dai_bac...@hotmail.com]
> Sent: Wednesday, July 06, 2011 10:11 AM
> To: php-general@lists.php.net
> Subject: Re: [PHP] Constants in strings
> 
> On Wed, 06 Jul 2011 12:56:21 +0100, Stuart Dallas wrote:
> > My guess is that the preceding $ causes PHP to interpret the next
> token
> > "{XYZ}" as a variable or a constant, but without that preceding $ it
> has
> > no way to know you're trying to use a constant. As Curtis points out,
> > the only way to insert a constant into a string is through
> > concatenation.
> >
> > -Stuart
> 
> OK. I should have made myself clearer - I was making an observation
> with
> regards to constant parsing in strings rather than looking for advice.
> My
> bad.
> 
> My third example showed that "{${XYZ}}" would echo the value of the
> variable called the value of XYZ:
>  define ('XYZ','ABC');
> 
> $ABC="huh!";
> 
> echo "{${XYZ}}\n";
> ?>
> Output - huh!
> 
> We could easily re-write the 'echo' line above to be:
> echo "{${constant('XYZ'}}\n";
> 
> But my example shows that PHP *is* accessing the value of a constant
> without any jiggery-pokery or hacks (e.g. http://www.php.net/manual/en/
> language.types.string.php#91628) as it is retrieving the value of ABC
> from the XYZ constant and then looking for a variable of that name.
> 
> I admit that I'm no C coder but it may be possible (note, the word
> "may")
> that a change of code within the PHP source tree will allow us to use
> something like echo "{{XYZ}}" to access the constant value.
> 
> Cheers
> 
> Dave
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php



define('DIR_JAVA', '/js/');

When you need to use the JavaScript directory you can do this.


There is no true need for the curly brackets to echo out the value of the 
constant.











--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Constants in strings

2011-07-06 Thread Dave Wilson
On Wed, 06 Jul 2011 12:56:21 +0100, Stuart Dallas wrote:
> My guess is that the preceding $ causes PHP to interpret the next token
> "{XYZ}" as a variable or a constant, but without that preceding $ it has
> no way to know you're trying to use a constant. As Curtis points out,
> the only way to insert a constant into a string is through
> concatenation.
> 
> -Stuart

OK. I should have made myself clearer - I was making an observation with 
regards to constant parsing in strings rather than looking for advice. My 
bad.

My third example showed that "{${XYZ}}" would echo the value of the 
variable called the value of XYZ:

Output - huh!

We could easily re-write the 'echo' line above to be:
echo "{${constant('XYZ'}}\n";

But my example shows that PHP *is* accessing the value of a constant 
without any jiggery-pokery or hacks (e.g. http://www.php.net/manual/en/
language.types.string.php#91628) as it is retrieving the value of ABC 
from the XYZ constant and then looking for a variable of that name.

I admit that I'm no C coder but it may be possible (note, the word "may") 
that a change of code within the PHP source tree will allow us to use 
something like echo "{{XYZ}}" to access the constant value.

Cheers

Dave


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Constants in strings

2011-07-06 Thread Ashley Sheridan


>> Any ideas?
>>
>echo XYZ  . "\n";
>
>
>
>--Curtis
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php

Which doesn't answer the original question Dave asked...

Thanks,
Ash
http://www.ashleysheridan.co.uk
--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Constants in strings

2011-07-06 Thread Stuart Dallas
On Wed, Jul 6, 2011 at 12:07 PM, Dave Wilson  wrote:

> Hi all,
>
> OK. We all know that constants cannot be accessed directly via their name
> in double-quoted or heredoc strings. I knew this already but a read of
> the PHP manual got me thinking.
>
> The manual states that to get the $$ value of a variable, the form
> "{${var}}" should be used. Therefore, I wondered if something similar
> would work for constants.
>
> Attempt 1 (just to be sure):
>  define ('XYZ','ABC');
> echo "{XYZ}\n";
> ?>
>
> Output - {XYZ}
>
> Attempt 2:
>  define ('XYZ','ABC');
> echo "{{XYZ}}\n";
> ?>
>
> Output - {{XYZ}}
>
> No luck there. I did encounter one oddity though:
>
>  define ('XYZ','ABC');
> echo "{${XYZ}}\n";
> ?>
>
> Output:
> PHP Notice: Undefined variable: ABC in /home/wilsond/testScripts/l7.php
> on line 3
>
> Which appears to mean that PHP is able to pick up the value of the
> constant and try to access a variable with that name.
>
> Any ideas?
>

My guess is that the preceding $ causes PHP to interpret the next token
"{XYZ}" as a variable or a constant, but without that preceding $ it has no
way to know you're trying to use a constant. As Curtis points out, the only
way to insert a constant into a string is through concatenation.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/


Re: [PHP] Constants in strings

2011-07-06 Thread Curtis Maurand

On 7/6/2011 7:07 AM, Dave Wilson wrote:

Output - {XYZ}

Attempt 2:


Output - {{XYZ}}

No luck there. I did encounter one oddity though:



Output:
PHP Notice: Undefined variable: ABC in /home/wilsond/testScripts/l7.php
on line 3

Which appears to mean that PHP is able to pick up the value of the
constant and try to access a variable with that name.

Any ideas?


echo XYZ  . "\n";



--Curtis


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] constants STDOUT, STDERR, STDIN not working in 5.2.x?

2010-03-24 Thread Jan G.B.
2010/3/24 Marten Lehmann 

> Hello,
>
>
>  dan...@daniel-laptop:~$ php test.php>  /dev/null
>> Error 1
>> Error 2
>> dan...@daniel-laptop:~$ ./src/php-5.2.12/sapi/cli/php test.php>
>>  /dev/null
>> Error 1
>> Error 2
>>
>
> well, using php-cli instead of php-cgi, this finally worked:
>
>  fwrite(STDERR, "test\n");
> fclose(STDERR);
> ?>
>
>
Weird, this does not work with the Ubuntu Version I'm using.
As reported in my previous email, I only can print out to STDERR when I
properly use php://stderr with fopen() - no matter if I use read or write
mode in fopen(). So be cautious when developing for different systems. Here
are some examples:

*** WORKS:
$ php

Foo

*** FAILURE:
##
$ php

Warning: fwrite(): supplied argument is not a valid stream resource in
/home/user/- on line 2

###
$ php

Foo
Warning: fwrite(): supplied argument is not a valid stream resource in
/home/user/- on line 2

###
$ php

// Nothing happens, no warning, no error and no "Foo"




But why doesn't it work with php-cgi? That's a binary that is called with
> the php-file is parameter the same way as php-cli. So both come with
> STDIN/STDOUT/STDERR contrary to scripts running through mod_php.
>
> What is the real difference between php-cli and php-cgi? This
> "fclose(STDERR);" is really important for one customer, because this is
> seems to be the only way to suppress later output to STDERR in the same
> script by external commands and functions that are too hard to change. But I
> don't want to break things for all other customers just to make one happier.
>

Well, see this..
$ php

string(6) "STDERR"

:-(


> Can the STDERR constands be enable somehow at compile-time for php-cgi?
>
> Regards
> Marten
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] constants STDOUT, STDERR, STDIN not working in 5.2.x?

2010-03-24 Thread Daniel Egeberg
On Wed, Mar 24, 2010 at 14:12, Marten Lehmann  wrote:
> Hello,
>
>> dan...@daniel-laptop:~$ php test.php>  /dev/null
>> Error 1
>> Error 2
>> dan...@daniel-laptop:~$ ./src/php-5.2.12/sapi/cli/php test.php>  /dev/null
>> Error 1
>> Error 2
>
> well, using php-cli instead of php-cgi, this finally worked:
>
>  fwrite(STDERR, "test\n");
> fclose(STDERR);
> ?>
>
> But why doesn't it work with php-cgi? That's a binary that is called with
> the php-file is parameter the same way as php-cli. So both come with
> STDIN/STDOUT/STDERR contrary to scripts running through mod_php.
>
> What is the real difference between php-cli and php-cgi? This
> "fclose(STDERR);" is really important for one customer, because this is
> seems to be the only way to suppress later output to STDERR in the same
> script by external commands and functions that are too hard to change. But I
> don't want to break things for all other customers just to make one happier.
>
> Can the STDERR constands be enable somehow at compile-time for php-cgi?
>
> Regards
> Marten

You can see how the CLI SAPI differs from the other SAPIs here:
http://php.net/manual/en/features.commandline.differences.php

-- 
Daniel Egeberg

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] constants STDOUT, STDERR, STDIN not working in 5.2.x?

2010-03-24 Thread Marten Lehmann

Hello,


dan...@daniel-laptop:~$ php test.php>  /dev/null
Error 1
Error 2
dan...@daniel-laptop:~$ ./src/php-5.2.12/sapi/cli/php test.php>  /dev/null
Error 1
Error 2


well, using php-cli instead of php-cgi, this finally worked:



But why doesn't it work with php-cgi? That's a binary that is called 
with the php-file is parameter the same way as php-cli. So both come 
with STDIN/STDOUT/STDERR contrary to scripts running through mod_php.


What is the real difference between php-cli and php-cgi? This 
"fclose(STDERR);" is really important for one customer, because this is 
seems to be the only way to suppress later output to STDERR in the same 
script by external commands and functions that are too hard to change. 
But I don't want to break things for all other customers just to make 
one happier.


Can the STDERR constands be enable somehow at compile-time for php-cgi?

Regards
Marten

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] constants STDOUT, STDERR, STDIN not working in 5.2.x?

2010-03-23 Thread Daniel Egeberg
On Tue, Mar 23, 2010 at 15:50, Jan G.B.  wrote:
>
>
> 2010/3/23 Daniel Egeberg 
>>
>> On Tue, Mar 23, 2010 at 11:47, Marten Lehmann  wrote:
>> > Hello,
>> >
>> > I found different code examples like this, which use the file handle
>> > STDERR
>> > just like this:
>> >
>> > > > fwrite(STDERR, "hello\n");
>> > ?>
>> >
>> > Also, the PHP documentation of input/output streams
>> > (http://php.net/manual/de/wrappers.php.php) says:
>> >
>> > "It is recommended that you simply use the constants STDIN, STDOUT  and
>> > STDERR instead of manually opening streams using these wrappers."
>> >
>> > I don't want to use the "php://stderr" wrapper, because this just
>> > creates a
>> > duplicate of the original STDERR handler and if I'm closing
>> > "php://stderr",
>> > the original STDERR still would exist.
>> >
>> > When I'm using this code, I only get:
>> >
>> > Notice:  Use of undefined constant STDERR - assumed 'STDERR' in
>> > /test.php on line 4
>> > 
>> > Warning:  fwrite(): supplied argument is not a valid stream
>> > resource
>> > in /test.php on line 4
>> >
>> > How can I access the original STDERR handle? The constant should be
>> > there,
>> > but does not exist.
>> >
>> > regards
>> > Marten
>>
>> These I/O streams are only present in the CLI SAPI.
>>
>> --
>> Daniel Egeberg
>>
> Please confirm that the code of my previous replay on this topic (executed
> via php-cli) does not print out "test2" or "test3". The constant is present
> but doesn't work as supposed.
> Regards
>
>

You are making a number of errors there:
1) You are trying to open php://stderr in read mode, but that stream
is write only (I'm not sure why it outputs regardless).
2) You are trying to open STDERR, but that constant holds a stream
resource while fopen() expects a string.
3) You are trying to write to 'php://stderr'. That's not possible. You
cannot pass a string as stream.

The following should work:

dan...@daniel-laptop:~$ cat test.php
 /dev/null
Error 1
Error 2
dan...@daniel-laptop:~$ ./src/php-5.2.12/sapi/cli/php test.php > /dev/null
Error 1
Error 2

-- 
Daniel Egeberg

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] constants STDOUT, STDERR, STDIN not working in 5.2.x?

2010-03-23 Thread Jan G.B.
2010/3/23 Daniel Egeberg 

> On Tue, Mar 23, 2010 at 11:47, Marten Lehmann  wrote:
> > Hello,
> >
> > I found different code examples like this, which use the file handle
> STDERR
> > just like this:
> >
> >  > fwrite(STDERR, "hello\n");
> > ?>
> >
> > Also, the PHP documentation of input/output streams
> > (http://php.net/manual/de/wrappers.php.php) says:
> >
> > "It is recommended that you simply use the constants STDIN, STDOUT  and
> > STDERR instead of manually opening streams using these wrappers."
> >
> > I don't want to use the "php://stderr" wrapper, because this just creates
> a
> > duplicate of the original STDERR handler and if I'm closing
> "php://stderr",
> > the original STDERR still would exist.
> >
> > When I'm using this code, I only get:
> >
> > Notice:  Use of undefined constant STDERR - assumed 'STDERR' in
> > /test.php on line 4
> > 
> > Warning:  fwrite(): supplied argument is not a valid stream
> resource
> > in /test.php on line 4
> >
> > How can I access the original STDERR handle? The constant should be
> there,
> > but does not exist.
> >
> > regards
> > Marten
>
> These I/O streams are only present in the CLI SAPI.
>
> --
> Daniel Egeberg
>
> Please confirm that the code of my previous replay on this topic (executed
via php-cli) does not print out "test2" or "test3". The constant is present
but doesn't work as supposed.

Regards


Re: [PHP] constants STDOUT, STDERR, STDIN not working in 5.2.x?

2010-03-23 Thread Daniel Egeberg
On Tue, Mar 23, 2010 at 11:47, Marten Lehmann  wrote:
> Hello,
>
> I found different code examples like this, which use the file handle STDERR
> just like this:
>
>  fwrite(STDERR, "hello\n");
> ?>
>
> Also, the PHP documentation of input/output streams
> (http://php.net/manual/de/wrappers.php.php) says:
>
> "It is recommended that you simply use the constants STDIN, STDOUT  and
> STDERR instead of manually opening streams using these wrappers."
>
> I don't want to use the "php://stderr" wrapper, because this just creates a
> duplicate of the original STDERR handler and if I'm closing "php://stderr",
> the original STDERR still would exist.
>
> When I'm using this code, I only get:
>
> Notice:  Use of undefined constant STDERR - assumed 'STDERR' in
> /test.php on line 4
> 
> Warning:  fwrite(): supplied argument is not a valid stream resource
> in /test.php on line 4
>
> How can I access the original STDERR handle? The constant should be there,
> but does not exist.
>
> regards
> Marten

These I/O streams are only present in the CLI SAPI.

-- 
Daniel Egeberg

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] constants STDOUT, STDERR, STDIN not working in 5.2.x?

2010-03-23 Thread Jan G.B.
2010/3/23 Marten Lehmann 

> Hello,
>
> I found different code examples like this, which use the file handle STDERR
> just like this:
>
>  fwrite(STDERR, "hello\n");
> ?>
>
> Also, the PHP documentation of input/output streams (
> http://php.net/manual/de/wrappers.php.php) says:
>
> "It is recommended that you simply use the constants STDIN, STDOUT  and
> STDERR instead of manually opening streams using these wrappers."
>
> I don't want to use the "php://stderr" wrapper, because this just creates a
> duplicate of the original STDERR handler and if I'm closing "php://stderr",
> the original STDERR still would exist.
>
> When I'm using this code, I only get:
>
> Notice:  Use of undefined constant STDERR - assumed 'STDERR' in
> /test.php on line 4
> 
> Warning:  fwrite(): supplied argument is not a valid stream resource
> in /test.php on line 4
>
> How can I access the original STDERR handle? The constant should be there,
> but does not exist.
>
> regards
> Marten
>
>
Hi,

I can reproduce it with some differences. Check this out:

 $ php --version
PHP 5.2.10-2ubuntu6.4 with Suhosin-Patch 0.9.7 (cli) (built: Jan  6 2010
22:56:44)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies

$ php 1>/dev/null # note that the PHP error messages are
displayed on STDOUT - I don't show them with "1>/dev/null"



---

Result:

test




So my assumption is, that the quoted recommendation is outdated / wrong.

Regards


PS: PHP reports this when giving the constant STDERR:
  Warning: fopen(STDERR): failed to open stream: No such file or directory
  Warning: fwrite(): supplied argument is not a valid stream resource


Re: [PHP] CONSTANTS and good coding practice

2004-05-21 Thread Jordi Canals
Al wrote:
Can someone explain to me the value of using defined custom constants, 
in the context of good coding practice.

I don't recall ever seeing define() used in the scripts I've seen and 
only the characteristics are described in the my php book and the php 
manual; but, not the use.

Talking about constants. I've seen the most scripts and web pages, (like 
some Open Source projects) They declare the database access values as 
vars not constants. I mean Username, Password, DataBase Name or Host.

In my point of view, this info is always constant on the script life, so 
it will be better to declare it as constants not as vars.

I normally declare as constants anything that will not change in the 
scripts life. Parhaps can change from one installation to another, but 
no more. Specially if I'm not completly sure that the value is correct 
for my purposes, I prefer to declare a constant and not directly write 
the value everywhere. It makes me easier to read and remember, and 
easier to change  in future if I need it.

For example, I think that :
if ($user_level == USR_LEVEL_WEBMASTER) {
// do stuff
}
is a lot easier to read and to imagine what we are looking for than:
if ($user_level == 255) {
// do stuff
}
Another way I use constants is when I want to pass to a function a sum 
of options. In this case imagine that function (Perhaps inside a class):

function draw_box($options) {
// do stuff
}
and this constants:
define('BOX_DRAW_BORDER', 1);
define('BOX_FILL_BACKGROUND', 2);
define('BOX_SHOW_TITLE', 4);
define('BOX_MAKE_LINKS' 8);
Then, I can call the function like this:
$box_options = BOX_DRAW_BORDER + BOX_FILL_BACKGROUND + BOX_MAKE_LINKS;
draw_box($box_options);
Finally, I normally use constants to declare all literal values that 
must be shown in the users browser. This is a need for me, beacuse in my 
country (Catalunya) we are bilinguals, and I have to be able to show 
literals in one or other language depending on the preferences. This 
makes scripts translation more easy, because I have all strings in one 
(or two) file.

I think, we should use constants always when we have a constant value 
(wich not will change on scrits' life).

Regards,
Jordi.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] CONSTANTS and good coding practice

2004-05-21 Thread Matt
> From: "Al" [EMAIL PROTECTED]   Friday, May 21, 2004 9:02 AM
> Subject: [PHP] CONSTANTS and good coding practice


> Can someone explain to me the value of using defined custom constants,
> in the context of good coding practice.

Constants are useful anywhere you find yourself typing a constant (i.e. 20,
'Ralph') and the value is used in more than one place in the code.  Say you
have a script that fetches 10 articles from a db, and then loads them into
an html table.  You could hard code the 10 into the sql statement, for loop,
while loop or what ever logic used to fetch and load the table. If you
instead used a constant, then when the client asks that the table now list
15 rows, all you need to do is change the value in one place in the code
instead of searching for 10 everywhere and evaluating if the 10 found has
anything to do with the logic. Arguably, you could use a variable for the
same purpose, but constants can't change value, and thus you protect
yourself from self inflicted coding injuries (as well as injection of values
over get, post, etc).

The only oddity I find in using constants in php, is that you can't use them
inside single or double quotes and always have to break out and use
concatenation.

---
The future will be better tomorrow
---
http://www.spiceplace.com/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Constants

2004-03-23 Thread Jakes
Thanks, will do.

"Red Wingate" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Give this a read:

http://marc.theaimsgroup.com/?l=php-dev&m=107936530102181&w=2

Am Dienstag, 23. März 2004 15:16 schrieb Red Wingate:
> IIRC it was changed to
>   self::CONST_NAME recently
>
> interface Settings {
>const UNAME = "somename";
>const PWORD = "password";
>const SERVER = "localhost";
> }
>
> class Conn implements Settings {
>public function  __construct(){
>$dbConn = mysql_connect(self::SERVER, self::UNAME,
self::PWORD);
>   }
> }
>
>  -- red

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Constants

2004-03-23 Thread Red Wingate
Give this a read:

http://marc.theaimsgroup.com/?l=php-dev&m=107936530102181&w=2

Am Dienstag, 23. März 2004 15:16 schrieb Red Wingate:
> IIRC it was changed to
>   self::CONST_NAME recently
>
> interface Settings {
>const UNAME = "somename";
>const PWORD = "password";
>const SERVER = "localhost";
> }
>
> class Conn implements Settings {
>public function  __construct(){
>$dbConn = mysql_connect(self::SERVER, self::UNAME, self::PWORD);
>   }
> }
>
>  -- red

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Constants

2004-03-23 Thread Red Wingate
IIRC it was changed to
  self::CONST_NAME recently

interface Settings {
   const UNAME = "somename";
   const PWORD = "password";
   const SERVER = "localhost";
}

class Conn implements Settings {
   public function  __construct(){
   $dbConn = mysql_connect(self::SERVER, self::UNAME, self::PWORD);
  }
}

 -- red

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Constants

2004-03-23 Thread Jakes
If you define constants with in a interface and then implement that
interface
it does not work on 5RC1

This should work, but it displays the constant name rather than value it
references

interface Settings {
   const UNAME = "somename";
   const PWORD = "password";
   const SERVER = "localhost";
}

class Conn implements Settings {
   public function  __construct(){
   $dbConn = mysql_connect(SERVER, UNAME, PWORD);
  }
}




"Jay Blanchard" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
[snip]
Not too fast.

>From http://www.php.net/zend-engine-2.php


PHP 5 introduces per-class constants:


[/snip]

My bad. Still not a bug.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Constants

2004-03-23 Thread Jay Blanchard
[snip]
Not too fast.

>From http://www.php.net/zend-engine-2.php


PHP 5 introduces per-class constants: 

 
[/snip]

My bad. Still not a bug. 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Constants

2004-03-23 Thread Vincent Jansen
Not too fast.

>From http://www.php.net/zend-engine-2.php


PHP 5 introduces per-class constants: 

 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Constants

2004-03-23 Thread Jay Blanchard
[snip]
displayFoo();
?>

The results should display "hello world", but it prints out MY_FOO.
[/snip]


This is not a bug, but a misunderstanding of constants. You have not
defined the constant

define("MY_FOO", "hello world.");

http://us4.php.net/constants

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Constants in class definitions

2004-02-23 Thread Adam Bregenzer
On Tue, 2004-02-24 at 09:26, Toro Hill wrote:
> Here's the situation:
> PHP 4.3.4
> Apache 1.3.29
> MMCache 2.4.6
> 
> I'm ending up with some garbage in certain class variables. 
> The code runs fine without MMCache disabled.
> There seems to be a very specific circumstances under which the error occurs. 
> Namely:
> 1. The constants must be defined in a seperate file.
> 2. The member array ($stuff, refer below) must be populated in the class definition, 
> not the class constructor 
> 3. index.php can't be modified after apache has been started. If I touch index.php 
> then the problem disappears, but then if I restart apache the problem reappears. 
> 
> If you want to see the output of the script go to http://outreach.net.nz/test/

Wow, looks like a bug to me, good find!

-- 
Adam Bregenzer
[EMAIL PROTECTED]
http://adam.bregenzer.net/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Constants in class definitions

2004-02-23 Thread Toro Hill
Hi Adam.
I was wondering if using defined constants in class definitions
is completely legal (or even good practice) in PHP. 
I've looked throught the PHP documentation and from what I can
tell it is legal.
However, I've had some problems with Turck MMCache and class definitions
that are similar to above. I suspect that it's probably a bug with 
MMCache but I wanted to check to make sure that the code was completely
correct. 

I also use MMCache, mind sharing the problems you are experiencing?
Here's the situation:
PHP 4.3.4
Apache 1.3.29
MMCache 2.4.6
I'm ending up with some garbage in certain class variables. 
The code runs fine without MMCache disabled.
There seems to be a very specific circumstances under which the error occurs. 
Namely:
1. The constants must be defined in a seperate file.
2. The member array ($stuff, refer below) must be populated in the class definition, not the class constructor 
3. index.php can't be modified after apache has been started. If I touch index.php then the problem disappears, but then if I restart apache the problem reappears. 

If you want to see the output of the script go to http://outreach.net.nz/test/

Here's the MMCache configuration:
extension="mmcache.so"
;shm_size="0" defaults to the OS default, which is 32M on my system
mmcache.shm_size="0"
mmcache.cache_dir="/tmp/mmcache"
mmcache.enable="1"
mmcache.optimizer="1"
mmcache.check_mtime="1"
mmcache.debug="0"
mmcache.filter=""
mmcache.shm_max="0"
mmcache.shm_ttl="0"
mmcache.shm_prune_period="0"
mmcache.shm_only="0"
mmcache.compress="1"
Here's the code:
index.php

require_once( "include.php" );
class Yep{
	var $stuff = array( 
			HELLO => 'nope', 
			goodbye => 'nah' );
	//var $stuff = array();
	function Yep(){
		/*$this->stuff = array( 
			HELLO => 'nope', 
			goodbye => 'nah' );*/
		echo 'yep constructor';
	}
	function stuff(){
		echo '';
		var_dump( $this->stuff );
		echo '';
	}
}
$yepper = new Yep();
$yepper->stuff();
echo '';
var_dump( $yepper );
?>

include.php

Thanks for the offer to share.
Toro
#
This e-mail message has been scanned for Viruses and Content and cleared 
by MailMarshal
For more information please visit www.marshalsoftware.com
#

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Constants in class definitions

2004-02-23 Thread Adam Bregenzer
On Tue, 2004-02-24 at 08:22, Toro Hill wrote:
> I've looked throught the PHP documentation and from what I can
> tell it is legal. I'm using PHP4.3.4, and haven't had any problems with 
> class definitions like this. 

I use constants in classes myself without problems.  In PHP 5 you can
actually declare constant class properties! :)

> However, I've had some problems with Turck MMCache and class definitions
> that are similar to above. I suspect that it's probably a bug with 
> MMCache but I wanted to check to make sure that the code was completely
> correct. 

I also use MMCache, mind sharing the problems you are experiencing?

-- 
Adam Bregenzer
[EMAIL PROTECTED]
http://adam.bregenzer.net/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Constants in class definitions

2004-02-23 Thread Richard Davey
Hello Toro,

Tuesday, February 24, 2004, 12:22:29 AM, you wrote:

TH> Hi all.
TH> I was wondering if using defined constants in class definitions
TH> is completely legal (or even good practice) in PHP.

I see absolutely no reason why not. Constants are just ways of
defining non-changing variables, there is nothing about them that
controls where they apply (i.e. their scope) and if anything the PHP
manual itself backs up the fact you can use them in a class:

"Like superglobals, the scope of a constant is global. You can access
constants anywhere in your script without regard to scope."

Global to me means what it says - global. In a class, a function, an
include, whatever.

-- 
Best regards,
 Richard Davey
 http://www.phpcommunity.org/wiki/296.html

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] constants

2003-07-21 Thread Haseeb






hi,
you can use constants whenever you want something whose value you don't want changed accidently.for e.g. i use a constant to keep track of the path.
if i am at the root level then i store "./" in it. and if i am one folder under the root then i store "../"  in it. now as i tend to name variables like this strPath (str for string) i often end up changing the value of strPath to something else in the script. to stop this from happening i use constants
 
HTH,
Haseeb
 
 
---Original Message---
 

From: Michael Müller
Date: Monday, July 21, 2003 04:22:03 PM
To: [EMAIL PROTECTED]
Subject: [PHP] constants
 
hi,
why should I use constants?
thx for help
 
Michael
 
 
 
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
 







  IncrediMail - Email has finally evolved - Click Here

RE: [PHP] Constants in heredoc strings?

2003-06-27 Thread Ford, Mike [LSS]
-Original Message-
From: Jeff Stewart

Is there a way to expand constants in heredoc strings without assigning
the
constant's value to a variable first?

--

No.

Cheers!

Mike

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Constants and "Here Document" Interpolation

2003-03-01 Thread Ernest E Vogelsinger
At 16:56 01.03.2003, Daniel R. Hansen said:
[snip]
>Can anyone tell me if it is possible (and how) to use defined constants
>within "here document" content?  I've not been successful finding anything
>on this in the online docs.
[snip] 

You simply could have tried it - it's trivial.

The answer: no, you cannot have a constant within a string, be it heredoc
or quoted. A constant must always reside on "native code level".

However you can easily concatenate strings and heredocs - both of the
examples below work correctly:

define('A_CONSTANT', 1);
$text1 = <<$text2";

Output:
This heredoc text contains the constant A_CONSTANT (1) outside the heredoc
construct...
This quoted text contains the constant A_CONSTANT (1) outside the string
quotes...


-- 
   >O Ernest E. Vogelsinger
   (\)ICQ #13394035
^ http://www.vogelsinger.at/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Constants and "Here Document" Interpolation

2003-03-01 Thread Danny Shepherd
Hello,

It doesn't look like it - a note in the constants manual entry reads:

"PHP has no way of recognizing the constant from any other string of
characters within the heredoc block"

Danny.

-Original Message-
From: Daniel R. Hansen [mailto:[EMAIL PROTECTED] 
Sent: 01 March 2003 15:57
To: [EMAIL PROTECTED]

Can anyone tell me if it is possible (and how) to use defined constants
within "here document" content?  I've not been successful finding anything
on this in the online docs.

Thanks!

Dan




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] "Constants" for dummies, please?

2003-02-21 Thread Philip Olson

Some thoughts on variables and constants:

a) You can't redefine a constant but can redefine
   a variable.

b) Constants are autoglobal (like superglobals) so
   for example:
   

   Had we not used global $variable, the $variable 
   would not have been available inside the function.
   But, the constant is AUTOglobal so it is.  Read:

 Variable Scope:
 http://www.php.net/variables.scope

c) Constants must be scalar values in PHP4, (so
   not arrays, objects, or resources).

d) Constants are cool, variables are cool too.

Regards,
Philip Olson


On Fri, 21 Feb 2003, Chris Corwin wrote:

> Help, please -- I've just started looking at my first line of PHP code.
> 
> :)
> 
> 
> A little background, I am *not really* a programmer: I went to art 
> school. 
> 
> I have taught myself to develop web stuff in another language: Lasso, 
> but have no training.
> 
> In any case, I am looking through a php script that I've downloaded, 
> and most of it makes at least some sense to me, but I have come upon:
> 
>
>   define('BASE', './');
>   include(BASE.'Functions/foo.php');
>   ?>
> 
> 
> Now, like any good lister, I checked the source first: php.net
> 
>  says:
> 
> "A constant is a identifier (name) for a simple value. As the name 
> suggests, that value cannot change during the execution of the script 
> (except the magic constants which aren't actually constants). A 
> constant is case-sensitive by default. By convention constant 
> identifiers are always uppercase. 
> 
> [...]
> 
> The scope of a constant is global--you can access it anywhere in your 
> script without regard to scope."
> 
> 
> 
> 
> So it is apparently *similar*, but not *exactly like* a variable, right?
> 
> Can anyone explain the difference to me?
> 
> A particular question I have is about what this phrase means:
> 
> "The scope of a constant is global--you can access it anywhere in your 
> script without regard to scope."
> 
> 
> 
> When it says "anywhere in your script" does that mean it's available to 
> "all of PHP"?
> 
> Or it is global to the rest of the file currently being processed, 
> regardless of namespace, unlike a "normal" variable which might be 
> unavailable in certain namespaces in the file?
> 
> Also, if anyone knows the subtleties of how any such differences effect 
> the rest of the script, that'd be wonderful, too.
> 
> 
> Thanks for any help!
> 
>   - me
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] constants and case sensitivity

2001-03-30 Thread Johnson, Kirk

I get the same results as you using PHP4. I can't explain this, since
constants are supposed to be case sensitive by default. They sure don't act
like they are. Looks like a bug to me.

Kirk

> -Original Message-
> From: almir [mailto:[EMAIL PROTECTED]]
> Sent: Friday, March 30, 2001 12:44 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP] constants and case sensitivity
> 
> 
> just when I thought , nice I didn't know how does it work  i 
> found out that
> it is not wroking anyhow if I put
> 
> define ("rights", "RIGHTS", X);
> define ("Rights", "RIGHTS", X);
> 
> echo rights . "->" .defined("rights") ."  " .Rights ."->"
> .defined("Rights")."";
> 
> regardless of X i always get
> RIGHTS->1 Rights->0
> but if i  change places of definiton it changes
> 
> define ("rights", "RIGHTS", X);
> define ("Rights", "RIGHTS", X);
> ..
>  Rights->0 RIGHTS->1
> 
> 
> again I am using 3.0.11 on IIS4
> 
> thanks
> 
> 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: 
> [EMAIL PROTECTED]
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] constants inside of a string

2001-01-10 Thread jeremy brand

No.

Jeremy Brand :: Sr. Software Engineer :: 408-245-9058 :: [EMAIL PROTECTED]
http://www.JeremyBrand.com/Jeremy/Brand/Jeremy_Brand.html for more 
Get your own Free, Private email at http://www.smackdown.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   ""   -- Quoted from Yahoo! homepage, http://www.yahoo.com

On Wed, 10 Jan 2001, jeff saenz wrote:

> Date: Wed, 10 Jan 2001 12:21:01 -0800
> From: jeff saenz <[EMAIL PROTECTED]>
> To: Joe Stump <[EMAIL PROTECTED]>
> Cc: [EMAIL PROTECTED]
> Subject: Re: [PHP] constants inside of a string
> 
> what about inside of a here doc
> 
> print << this is the MAX
> HERE
> 
> Joe Stump wrote:
> 
> > print "the max is ".MAX;
> >
> > --Joe
> >
> > On Wed, Jan 10, 2001 at 12:12:08PM -0800, jeff saenz wrote:
> > > how do you use defines inside of a string...
> > >
> > > e.g.
> > >
> > > define(MAX,2);
> > > print  "the max is MAX";
> > >
> > > this obv does not work
> > >
> > > jeff
> > >
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > To contact the list administrators, e-mail: [EMAIL PROTECTED]
> >
> > ---
> > Joe Stump
> > PHP Programmer
> > www.Care2.com
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
> 
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] constants inside of a string

2001-01-10 Thread jeremy brand

> define(MAX,2);
> print  "the max is MAX";
> 
> this obv does not work

print "the max is " . MAX;


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] constants inside of a string

2001-01-10 Thread Toby Butzon

This reminded me of an issue I've kind of been contemplating
for a couple of weeks now... I got sick of having to
connect, query, check for errors, etc. every time I wanted
to query a mysql database, so I wrote a function to do all
of it for me... something like:

function query_db($queryString, $file, $line) {
// do db stuff
// if error, die using $file and $line (actually using
constants __FILE__ and __LINE__ only tell me that it died in
this function)
// return results of query
}

Now, to call the function I've been using:

$result = query_db("SELECT * FROM myTable", __FILE__,
__LINE__);

It'd be nice to be able to get __FILE__ and __LINE__ where
the function was called without passing them as parameters.
Even if I could just define a macro _HERE_ to expand into
__FILE__, __LINE__ it would save me some time...

I know it sounds lazy, but if there was a way so I could
just call

$result = query_db("SELECT * FROM myTable");

it'd be so much nicer...

PS - I don't want to get into db abstraction and all that...
I just wonder if what I'm talking about is easy/possible.

Thanks for input -

--Toby

- Original Message -
From: "Moritz Petersen" <[EMAIL PROTECTED]>
Sent: Wednesday, January 10, 2001 3:18 PM
Subject: RE: [PHP] constants inside of a string




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] constants inside of a string

2001-01-10 Thread Joe Stump

I'm not sure about that one - I think most variables work. No better way to find
out than to try it ;o)

--Joe


On Wed, Jan 10, 2001 at 12:21:01PM -0800, jeff saenz wrote:
> what about inside of a here doc
> 
> print << this is the MAX
> HERE
> 
> Joe Stump wrote:
> 
> > print "the max is ".MAX;
> >
> > --Joe
> >
> > On Wed, Jan 10, 2001 at 12:12:08PM -0800, jeff saenz wrote:
> > > how do you use defines inside of a string...
> > >
> > > e.g.
> > >
> > > define(MAX,2);
> > > print  "the max is MAX";
> > >
> > > this obv does not work
> > >
> > > jeff
> > >
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > To contact the list administrators, e-mail: [EMAIL PROTECTED]
> >
> > ---
> > Joe Stump
> > PHP Programmer
> > www.Care2.com
> 

---
Joe Stump
PHP Programmer
www.Care2.com


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] constants inside of a string

2001-01-10 Thread jeff saenz

what about inside of a here doc

print << print "the max is ".MAX;
>
> --Joe
>
> On Wed, Jan 10, 2001 at 12:12:08PM -0800, jeff saenz wrote:
> > how do you use defines inside of a string...
> >
> > e.g.
> >
> > define(MAX,2);
> > print  "the max is MAX";
> >
> > this obv does not work
> >
> > jeff
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
> ---
> Joe Stump
> PHP Programmer
> www.Care2.com


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] constants inside of a string

2001-01-10 Thread Joe Stump

print "the max is ".MAX;

--Joe

On Wed, Jan 10, 2001 at 12:12:08PM -0800, jeff saenz wrote:
> how do you use defines inside of a string...
> 
> e.g.
> 
> define(MAX,2);
> print  "the max is MAX";
> 
> this obv does not work
> 
> jeff
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]

---
Joe Stump
PHP Programmer
www.Care2.com


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] constants inside of a string

2001-01-10 Thread Moritz Petersen

> how do you use defines inside of a string...
> 
> e.g.
> 
> define(MAX,2);
> print  "the max is MAX";

print "the max is " . MAX;

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]