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 =EoSQL
SELECT
foo AS Foo
FROM Bar
WHERE baz='quux'
EoSQL;


--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

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



[PHP] Constants in strings

2011-07-06 Thread Dave Wilson
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):
?php
define ('XYZ','ABC');
echo {XYZ}\n;
?

Output - {XYZ}

Attempt 2:
?php
define ('XYZ','ABC');
echo {{XYZ}}\n;
?

Output - {{XYZ}}

No luck there. I did encounter one oddity though:

?php
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?

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 Curtis Maurand

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

Output - {XYZ}

Attempt 2:
?php
define ('XYZ','ABC');
echo {{XYZ}}\n;
?

Output - {{XYZ}}

No luck there. I did encounter one oddity though:

?php
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?


echo XYZ  . \n;



--Curtis


--
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 dai_bac...@hotmail.com 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):
 ?php
 define ('XYZ','ABC');
 echo {XYZ}\n;
 ?

 Output - {XYZ}

 Attempt 2:
 ?php
 define ('XYZ','ABC');
 echo {{XYZ}}\n;
 ?

 Output - {{XYZ}}

 No luck there. I did encounter one oddity though:

 ?php
 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 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 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:
?php
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



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:
 ?php
 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.
script src=?php echo DIR_JAVA . 'jquery-1.5.1.js';?/script

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.
script src=?php echo DIR_JAVA . 'jquery-1.5.1.js';?/script

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 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:
 ?php
 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.
 script
src=?php echo DIR_JAVA .
'jquery-1.5.1.js';?/script
 

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 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.
 script src=?php echo DIR_JAVA . 'jquery-1.5.1.js';?/script
 
 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 EOT
Your constant for the JavaScript path is {{DIR_JAVA}}
EOT; 

I fully understand the syntax but I do not understand the advantages of using 
either.
Is it just a writing style, or is there an advantage to the way it processes, 
speed or something?





 


--
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
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:

?php

$accountCreationSuccessfulMessage = EndSuccess
Pellentesque habitant morbi tristique senectus et netus et malesuada fames
ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget,
tempor sit amet, ante.

Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae
est.

Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper
pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit
amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum
rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis
pulvinar facilisis. Ut felis.
EndSuccess



$accountCreationFailedMessage = EndFailure
Donec placerat. Nullam nibh dolor, blandit sed, fermentum id, imperdiet
sit amet, neque. Nam mollis ultrices justo. Sed tempor. Sed vitae tellus.
Etiam sem arcu, eleifend sit amet, gravida eget, porta at, wisi. Nam non
lacus vitae ipsum viverra pretium. Phasellus massa.

Fusce magna sem, gravida in, feugiat ac, molestie eget, wisi. Fusce
consectetuer luctus ipsum. Vestibulum nunc. Suspendisse dignissim
adipiscing libero. Integer leo. Sed pharetra ligula a dui. Quisque ipsum
nibh, ullamcorper eget, pulvinar sed, posuere vitae, nulla. Sed varius
nibh ut lacus. Curabitur fringilla.

Nunc est ipsum, pretium quis, dapibus sed, varius non, lectus. Proin a
quam. Praesent lacinia, eros quis aliquam porttitor, urna lacus volutpat
urna, ut fermentum neque mi egestas dolor.
EndFailure



?

Of course, this is arguably as clean:

?php

$accountCreationSuccessfulMessage = 
Pellentesque habitant morbi tristique senectus et netus et malesuada fames
ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget,
tempor sit amet, ante.

Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae
est.

Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper
pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit
amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum
rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis
pulvinar facilisis. Ut felis.
; //$accountCreationSuccessfulMessage

$accountCreationFailedMessage = 
Donec placerat. Nullam nibh dolor, blandit sed, fermentum id, imperdiet
sit amet, neque. Nam mollis ultrices justo. Sed tempor. Sed vitae tellus.
Etiam sem arcu, eleifend sit amet, gravida eget, porta at, wisi. Nam non
lacus vitae ipsum viverra pretium. Phasellus massa.

Fusce magna sem, gravida in, feugiat ac, molestie eget, wisi. Fusce
consectetuer luctus ipsum. Vestibulum nunc. Suspendisse dignissim
adipiscing libero. Integer leo. Sed pharetra ligula a dui. Quisque ipsum
nibh, ullamcorper eget, pulvinar sed, posuere vitae, nulla. Sed varius
nibh ut lacus. Curabitur fringilla.

Nunc est ipsum, pretium quis, dapibus sed, varius non, lectus. Proin a
quam. Praesent lacinia, eros quis aliquam porttitor, urna lacus volutpat
urna, ut fermentum neque mi egestas dolor.
; //$accountCreationFailedMessage

?

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 

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 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:


?php

$blah = _
Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo consequat.
_;

?

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 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:

?
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

--
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 lehm...@cnm.de 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 Jan G.B.
2010/3/24 Marten Lehmann lehm...@cnm.de

 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
?php $x = fopen('php://stderr', 'w'); fwrite($x, 'Foo'); fclose($x); ?
Foo

*** FAILURE:
##
$ php
?
fwrite(STDERR, test);
?
Warning: fwrite(): supplied argument is not a valid stream resource in
/home/user/- on line 2

###
$ php
?php $x = fopen('php://stderr', 'w'); fwrite($x, 'Foo');
fwrite(STDERR, 'Bar');
fclose($x); ?
Foo
Warning: fwrite(): supplied argument is not a valid stream resource in
/home/user/- on line 2

###
$ php
?php $x = fopen(STDERR, 'w'); fwrite($x, 'Foo'); fclose($x); ?
// 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
? var_dump(STDERR); ?
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




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

2010-03-23 Thread Marten Lehmann

Hello,

I found different code examples like this, which use the file handle 
STDERR just like this:


?php
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:

bNotice/b:  Use of undefined constant STDERR - assumed 'STDERR' in 
b/test.php/b on line b4/bbr /

br /
bWarning/b:  fwrite(): supplied argument is not a valid stream 
resource in b/test.php/b on line b4/bbr /


How can I access the original STDERR handle? The constant should be 
there, but does not exist.


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 Jan G.B.
2010/3/23 Marten Lehmann lehm...@cnm.de

 Hello,

 I found different code examples like this, which use the file handle STDERR
 just like this:

 ?php
 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:

 bNotice/b:  Use of undefined constant STDERR - assumed 'STDERR' in
 b/test.php/b on line b4/bbr /
 br /
 bWarning/b:  fwrite(): supplied argument is not a valid stream resource
 in b/test.php/b on line b4/bbr /

 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
?
$x = fopen('php://stderr', 'r'); fwrite($x, test\n); fclose($x);
$x = fopen(STDERR, 'r'); fwrite($x, test2\n); fclose($x); ?

?
fwrite(STDERR, test3\n);
fwrite ('php://stderr', test4);
?
---

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 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 lehm...@cnm.de wrote:
 Hello,

 I found different code examples like this, which use the file handle STDERR
 just like this:

 ?php
 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:

 bNotice/b:  Use of undefined constant STDERR - assumed 'STDERR' in
 b/test.php/b on line b4/bbr /
 br /
 bWarning/b:  fwrite(): supplied argument is not a valid stream resource
 in b/test.php/b on line b4/bbr /

 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 Daniel Egeberg degeb...@php.net

 On Tue, Mar 23, 2010 at 11:47, Marten Lehmann lehm...@cnm.de wrote:
  Hello,
 
  I found different code examples like this, which use the file handle
 STDERR
  just like this:
 
  ?php
  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:
 
  bNotice/b:  Use of undefined constant STDERR - assumed 'STDERR' in
  b/test.php/b on line b4/bbr /
  br /
  bWarning/b:  fwrite(): supplied argument is not a valid stream
 resource
  in b/test.php/b on line b4/bbr /
 
  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 15:50, Jan G.B. ro0ot.w...@googlemail.com wrote:


 2010/3/23 Daniel Egeberg degeb...@php.net

 On Tue, Mar 23, 2010 at 11:47, Marten Lehmann lehm...@cnm.de wrote:
  Hello,
 
  I found different code examples like this, which use the file handle
  STDERR
  just like this:
 
  ?php
  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:
 
  bNotice/b:  Use of undefined constant STDERR - assumed 'STDERR' in
  b/test.php/b on line b4/bbr /
  br /
  bWarning/b:  fwrite(): supplied argument is not a valid stream
  resource
  in b/test.php/b on line b4/bbr /
 
  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
?php
$stderr = fopen('php://stderr', 'w');
fwrite($stderr, 'Error 1' . PHP_EOL);
fwrite(STDERR, 'Error 2' . PHP_EOL);
echo 'Normal echo';
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

-- 
Daniel Egeberg

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



[PHP] CONSTANTS and good coding practice

2004-05-21 Thread Al
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.

Thanks.
--
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 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

2004-03-23 Thread Jay Blanchard
[snip]
?php
   interface Foo {
  const MY_FOO = hello world;
 }
class Bar implements Foo  {
public function displayFoo(){
   print MY_FOO;
}
}
$obj = new Bar;
  $obj-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

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
class Foo {
   const constant = constant;
}

echo Foo::constant =  . Foo::constant . \n;
? 

-- 
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: 

?php
class Foo {
   const constant = constant;
}

echo Foo::constant =  . Foo::constant . \n;
? 
[/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 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:

?php
class Foo {
   const constant = constant;
}

echo Foo::constant =  . Foo::constant . \n;
?
[/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 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-devm=107936530102181w=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 Jakes
Thanks, will do.

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

http://marc.theaimsgroup.com/?l=php-devm=107936530102181w=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



[PHP] Constants

2004-03-22 Thread Jakes
The bug server looks like its down, so I will just post the bug here, and
hopefully someone
will spot it

PHP version: 5RC1

?php
   interface Foo {
  const MY_FOO = hello world;
 }
class Bar implements Foo  {
public function displayFoo(){
   print MY_FOO;
}
}
$obj = new Bar;
  $obj-displayFoo();
?

The results should display hello world, but it prints out MY_FOO.

Thanks

Jakes

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



[PHP] Constants in class definitions

2004-02-23 Thread Toro Hill
Hi all.
I was wondering if using defined constants in class definitions
is completely legal (or even good practice) in PHP.
For example, 
?php
define( CONSTANT, hello );
class Yep{
  $var stuff = array( CONSTANT = 'two' );
}
?

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. 

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. 

The following seems to work fine with MMCache,
?php
define( CONSTANT, hello );
class Yep{
  $var stuff = NULL;
  function Yep(){
 $this-stuff = array( CONSTANT = 'two' );
  }
}
?
If it turns out that the first example is fine, then I'll look a submitting
a bug for MMCache.
Thanks
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 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 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 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
?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 constructorbr';
	}
	function stuff(){
		echo 'pre';
		var_dump( $this-stuff );
		echo '/pre';
	}
}
$yepper = new Yep();
$yepper-stuff();
echo 'br';
var_dump( $yepper );
?

include.php
?php
define( 'HELLO', 'hello' );
define( 'goodbye', 'GOODBYE' );
?
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 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



[PHP] constants

2003-07-21 Thread Michael Müller
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



Re: [PHP] constants

2003-07-21 Thread Haseeb






hi,
you can use constantswhenever you want something whosevalue 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 istore "../" 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

[PHP] Constants in heredoc strings?

2003-06-27 Thread Jeff Stewart
Is there a way to expand constants in heredoc strings without assigning the
constant's value to a variable first?

--
Jeff S.



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



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



[PHP] Constants and Here Document Interpolation

2003-03-01 Thread Daniel R. Hansen
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 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 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 = EOT
This heredoc text contains the constant A_CONSTANT (
EOT
. A_CONSTANT .  EOT
) outside the heredoc construct...
EOT;

$text2 = This quoted text contains the constant A_CONSTANT ( .
 A_CONSTANT .
 ) outside the string quotes...;
echo $text1br /$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



FW: [PHP] Constants and Here Document Interpolation

2003-03-01 Thread Daniel R. Hansen
Actually I did try it and couldn't think of a way to work around the matter.
Thanks for the suggestion.

-Original Message-
From: Ernest E Vogelsinger [mailto:[EMAIL PROTECTED]
Sent: Saturday, March 01, 2003 12:56 PM
To: Daniel R. Hansen
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] Constants and Here Document Interpolation


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 = EOT
This heredoc text contains the constant A_CONSTANT (
EOT
. A_CONSTANT .  EOT
) outside the heredoc construct...
EOT;

$text2 = This quoted text contains the constant A_CONSTANT ( .
 A_CONSTANT .
 ) outside the string quotes...;
echo $text1br /$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: FW: [PHP] Constants and Here Document Interpolation

2003-03-01 Thread Ernest E Vogelsinger
At 19:28 01.03.2003, Daniel R. Hansen said:
[snip]
Actually I did try it and couldn't think of a way to work around the matter.
Thanks for the suggestion.

-Original Message-
From: Ernest E Vogelsinger [mailto:[EMAIL PROTECTED]
You simply could have tried it - it's trivial.

 [blah]
[snip] 

My apologies - by rereading my message it sounds straightforward arrogant
which it wasn't meant to be. I was referring to your statement didn't find
anything in the online docs that led me to the perception you didn't even
try it - sorry for that (but there are so many posters asking questions
that wouldn't even arise if they only had _tried_ it).

Hope my suggestion helps though :-)


-- 
   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



[PHP] Constants for dummies, please?

2003-02-21 Thread Chris Corwin
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:

?php

define('BASE', './');
include(BASE.'Functions/foo.php');
?


Now, like any good lister, I checked the source first: php.net

http://www.php.net/manual/en/language.constants.php 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




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:
   ?php
 define ('CONSTANT', 'some value');
 $variable = 'some value';

 function foo() {
 global $variable;

 print $variable;
 print CONSTANT;
 }
 foo();
   ?

   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:
 
   ?php
 
   define('BASE', './');
   include(BASE.'Functions/foo.php');
   ?
 
 
 Now, like any good lister, I checked the source first: php.net
 
 http://www.php.net/manual/en/language.constants.php 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



[PHP] constants and sessions

2002-11-12 Thread Eduardo M. Bragatto
	I have to change the constant maximum_time_out (via
set_timeout_limit) on the first script, and keep it seted
in a session, until the second script became to be loaded.
Is that possible?

		[[]]'s Bragatto

PS: sorry for my miserable english #)



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




[PHP] constants and case sensitivity

2001-03-30 Thread almir

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")."br";

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]




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")."br";
 
 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 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

snip


-- 
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]