PHP_EOL exposed to scripts?

php.internals

Paul Hudson

22 years ago
Hi there, This may already have been considered in the past, but I was wondering whether the PHP_EOL constant available inside the PHP source code could be made available to PHP programmers in their scripts? The current solution is, of course, to check PHP_OS each time and set the constant by hand, but it would be nicer to have it pre-defined. The cons are: 1) will break scripts that define their own PHP_EOL; and 2) people might use it without realising it changes across platforms (duh?), and rely on it to always be \n (or \r\n, etc); 3) Other cons? Anyway, the patch is predictably easy: add this line in main.c, after the definition for PHP_SHLIB_SUFFIX: REGISTER_MAIN_STRINGL_CONSTANT("PHP_EOL", PHP_EOL, sizeof(PHP_EOL)-1, CONST_PERSISTENT | CONST_CS); I've attached a diff, such as it is. Thanks, Paul

Andi Gutmans

22 years ago
I think it's a good idea. Personally I think that making this EOL would make it even easier to use. We tend to prefix constants but in this case, we should probably consider not doing so because it could be part of the language. Andi At 12:22 AM 8/12/2004 +0100, Paul Hudson wrote:

Derick Rethans

22 years ago
On Wed, 11 Aug 2004, Andi Gutmans wrote:
> I think it's a good idea. Personally I think that making this EOL would > make it even easier to use.
We can't do that because I bet it's a constant that many people have done in their own scripts. So IMO PHP_EOL is the way to go. I already patch 5.0.x and 5.1.x for this, just need to commit it (when I hear more opinions of course). Derick

Andi Gutmans

22 years ago
At 09:23 AM 8/12/2004 +0200, Derick Rethans wrote:
>On Wed, 11 Aug 2004, Andi Gutmans wrote: > > > I think it's a good idea. Personally I think that making this EOL would > > make it even easier to use. > >We can't do that because I bet it's a constant that many people have >done in their own scripts. So IMO PHP_EOL is the way to go.
You have a point that probably many people already have EOL defined. Well I guess that if someone doesn't like the "too" verbose PHP_EOL they can always re-define it to EOL in their prepend. Most important is that this constant exists as it's very useful.
>I already patch 5.0.x and 5.1.x for this, just need to commit it (when I >hear more opinions of course).
Sounds good to me. Andi

Derick Rethans

22 years ago
On Thu, 12 Aug 2004, Andi Gutmans wrote:
> At 09:23 AM 8/12/2004 +0200, Derick Rethans wrote: > >On Wed, 11 Aug 2004, Andi Gutmans wrote: > > > > > I think it's a good idea. Personally I think that making this EOL would > > > make it even easier to use. > > > >We can't do that because I bet it's a constant that many people have > >done in their own scripts. So IMO PHP_EOL is the way to go. > > You have a point that probably many people already have EOL defined. Well I > guess that if someone doesn't like the "too" verbose PHP_EOL they can > always re-define it to EOL in their prepend. Most important is that this > constant exists as it's very useful. > > >I already patch 5.0.x and 5.1.x for this, just need to commit it (when I > >hear more opinions of course). > > Sounds good to me.
Committed for 5.0.2 and 5.1.0 Derick