By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,696 Members | 2,213 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,696 IT Pros & Developers. It's quick & easy.

.php5 versus .php

P: n/a
I am working in two environments neither configuration of
which I can change; one's my Web host the other a client.

My Web host requires the use of the ".php5" extension
to use PHP v5.1.4; where ".php" is used for PHP v4.3.11.
My client supports PHP v5.2.0 with the ".php" extension.

Is there a way to reliably determine if the ".php5" extension
must be used on a server? Perhaps via a "phpinfo()" value?

I have a page that uses the v5 function "file_put_contents()".
(I like it's LOCK_EX feature.)

Thanks in advance.
Feb 15 '07 #1
Share this Question
Share on Google+
19 Replies


P: n/a
"McKirahan" <Ne**@McKirahan.comwrote in message
news:dO******************************@comcast.com. ..
I am working in two environments neither configuration of
which I can change; one's my Web host the other a client.

My Web host requires the use of the ".php5" extension
to use PHP v5.1.4; where ".php" is used for PHP v4.3.11.
My client supports PHP v5.2.0 with the ".php" extension.

Is there a way to reliably determine if the ".php5" extension
must be used on a server? Perhaps via a "phpinfo()" value?

I have a page that uses the v5 function "file_put_contents()".
(I like it's LOCK_EX feature.)

Thanks in advance.

I tried this (to not write to the file in the function isn't supported):

try {
file_put_contents($file, $text, FILE_APPEND+LOCK_EX);
} catch (Exception $e) {
echo "Caught exception: ", $e->getMessage(), "\n";
}

but got this error:

Parse error: parse error, unexpected '{' ...

It doesn't like my use of "try - catch".
Why isn't "try - catch" documented?
I found only one reference; (under "Exceptions").
Feb 15 '07 #2

P: n/a
Rik
On Thu, 15 Feb 2007 18:12:30 +0100, McKirahan <Ne**@McKirahan.comwrote:
>Is there a way to reliably determine if the ".php5" extension
must be used on a server? Perhaps via a "phpinfo()" value?
I tried this (to not write to the file in the function isn't supported):

try {
file_put_contents($file, $text, FILE_APPEND+LOCK_EX);
} catch (Exception $e) {
echo "Caught exception: ", $e->getMessage(), "\n";
}

but got this error:

Parse error: parse error, unexpected '{' ...

It doesn't like my use of "try - catch".
Why isn't "try - catch" documented?
I found only one reference; (under "Exceptions").
try - catch is only usefull for Exceptions, and hence that's where they're
found. Also, Exceptions are introduced in PHP5, so that's no way to fall
back to PHP4.

Usefull for determening current PHP / newer functionality:
<http://www.php.net/phpversion>
<http://pear.php.net/package/PHP_Compat>

Now, I have no idea how to find out the addtype declarations in apaches
configuration with PHP, but this cumbersome workaround will probably work:

----checktype.php5--
echo PHP_VERSION;
--------------------

---check.php--------
echo "Current .php version is ".PHP_VERSION."\n";
$path = 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/';
$php5 = file_get_contents($path.'checktype.php5');
if(preg_match('/^<\?/',$php5)){
echo ".php5 is not supported as an extention";
} else {
echo ".php5 uses version ".$php5;
$result = version_compare(PHP_VERSION,$php5);
if($result == 0){
echo "\nversions are equal";
} else {
echo "\nversion used for .php5 is ".(($result==-1)?'higher':'lower');
}
}
--------------------

--
Rik Wasmus
Feb 15 '07 #3

P: n/a
McKirahan kirjoitti:
"McKirahan" <Ne**@McKirahan.comwrote in message
news:dO******************************@comcast.com. ..
>I am working in two environments neither configuration of
which I can change; one's my Web host the other a client.

My Web host requires the use of the ".php5" extension
to use PHP v5.1.4; where ".php" is used for PHP v4.3.11.
My client supports PHP v5.2.0 with the ".php" extension.

Is there a way to reliably determine if the ".php5" extension
must be used on a server? Perhaps via a "phpinfo()" value?

I have a page that uses the v5 function "file_put_contents()".
(I like it's LOCK_EX feature.)

Thanks in advance.


I tried this (to not write to the file in the function isn't supported):

try {
file_put_contents($file, $text, FILE_APPEND+LOCK_EX);
} catch (Exception $e) {
echo "Caught exception: ", $e->getMessage(), "\n";
}

but got this error:

Parse error: parse error, unexpected '{' ...

It doesn't like my use of "try - catch".
Why isn't "try - catch" documented?
I found only one reference; (under "Exceptions").

Don't know if these help you any but two observations:

1) you can get the version of php with phpversion();
http://fi.php.net/manual/en/function.phpversion.php

2) You can test wether a function exists with

if(function_exists('file_put_contents')){
file_put_contents($file, $text, FILE_APPEND+LOCK_EX);
} else {
echo "craptastic!";
}
--
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)
Feb 15 '07 #4

P: n/a
On Feb 15, 6:05 pm, Kimmo Laine <s...@outolempi.netwrote:
McKirahan kirjoitti:
"McKirahan" <N...@McKirahan.comwrote in message
news:dO******************************@comcast.com. ..
I am working in two environments neither configuration of
which I can change; one's my Web host the other a client.
My Web host requires the use of the ".php5" extension
to use PHP v5.1.4; where ".php" is used for PHP v4.3.11.
My client supports PHP v5.2.0 with the ".php" extension.
Is there a way to reliably determine if the ".php5" extension
must be used on a server? Perhaps via a "phpinfo()" value?
I have a page that uses the v5 function "file_put_contents()".
(I like it's LOCK_EX feature.)
Thanks in advance.
I tried this (to not write to the file in the function isn't supported):
try {
file_put_contents($file, $text, FILE_APPEND+LOCK_EX);
} catch (Exception $e) {
echo "Caught exception: ", $e->getMessage(), "\n";
}
but got this error:
Parse error: parse error, unexpected '{' ...
It doesn't like my use of "try - catch".
Why isn't "try - catch" documented?
I found only one reference; (under "Exceptions").

Don't know if these help you any but two observations:

1) you can get the version of php with phpversion();http://fi.php.net/manual/en/function.phpversion.php

2) You can test wether a function exists with

if(function_exists('file_put_contents')){
file_put_contents($file, $text, FILE_APPEND+LOCK_EX);} else {

echo "craptastic!";

}

--
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
s...@outolempi.net | Gedoon-S @ IRCnet | rot13(x...@bhgbyrzcv.arg)
also your code had a typo in it:

try
{
file_put_contents($file, $text, FILE_APPEND+LOCK_EX);
}
catch (Exception $e)
{
echo "Caught exception: ". $e->getMessage(), "\n";
} |
__________________________|
(should have been a dot after caught exception)

as for .php5, just use an .htaccess file to rewrite all extensions of
one sort to the other, whatever suits. 1and1 are like this, but the
htaccess rewrite rules work fine.

Feb 15 '07 #5

P: n/a
On Feb 15, 6:05 pm, Kimmo Laine <s...@outolempi.netwrote:
McKirahan kirjoitti:
"McKirahan" <N...@McKirahan.comwrote in message
news:dO******************************@comcast.com. ..
I am working in two environments neither configuration of
which I can change; one's my Web host the other a client.
My Web host requires the use of the ".php5" extension
to use PHP v5.1.4; where ".php" is used for PHP v4.3.11.
My client supports PHP v5.2.0 with the ".php" extension.
Is there a way to reliably determine if the ".php5" extension
must be used on a server? Perhaps via a "phpinfo()" value?
I have a page that uses the v5 function "file_put_contents()".
(I like it's LOCK_EX feature.)
Thanks in advance.
I tried this (to not write to the file in the function isn't supported):
try {
file_put_contents($file, $text, FILE_APPEND+LOCK_EX);
} catch (Exception $e) {
echo "Caught exception: ", $e->getMessage(), "\n";
}
but got this error:
Parse error: parse error, unexpected '{' ...
It doesn't like my use of "try - catch".
Why isn't "try - catch" documented?
I found only one reference; (under "Exceptions").

Don't know if these help you any but two observations:

1) you can get the version of php with phpversion();http://fi.php.net/manual/en/function.phpversion.php

2) You can test wether a function exists with

if(function_exists('file_put_contents')){
file_put_contents($file, $text, FILE_APPEND+LOCK_EX);} else {

echo "craptastic!";

}

--
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
s...@outolempi.net | Gedoon-S @ IRCnet | rot13(x...@bhgbyrzcv.arg)
oh and of course, dont forget the other typo ,->. further on the same
line!!

Feb 15 '07 #6

P: n/a
"Rik" <lu************@hotmail.comwrote in message
news:op.tnsw4xtiqnv3q9@misant...
On Thu, 15 Feb 2007 18:12:30 +0100, McKirahan <Ne**@McKirahan.comwrote:
>Is there a way to reliably determine if the ".php5" extension
must be used on a server? Perhaps via a "phpinfo()" value?
I tried this (to not write to the file in the function isn't supported):

try {
file_put_contents($file, $text, FILE_APPEND+LOCK_EX);
} catch (Exception $e) {
echo "Caught exception: ", $e->getMessage(), "\n";
}

but got this error:

Parse error: parse error, unexpected '{' ...

It doesn't like my use of "try - catch".
Why isn't "try - catch" documented?
I found only one reference; (under "Exceptions").
try - catch is only usefull for Exceptions, and hence that's where they're
found. Also, Exceptions are introduced in PHP5, so that's no way to fall
back to PHP4.

Usefull for determening current PHP / newer functionality:
<http://www.php.net/phpversion>
<http://pear.php.net/package/PHP_Compat>

Now, I have no idea how to find out the addtype declarations in apaches
configuration with PHP, but this cumbersome workaround will probably work:

----checktype.php5--
echo PHP_VERSION;
--------------------

---check.php--------
echo "Current .php version is ".PHP_VERSION."\n";
$path = 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/';
$php5 = file_get_contents($path.'checktype.php5');
if(preg_match('/^<\?/',$php5)){
echo ".php5 is not supported as an extention";
} else {
echo ".php5 uses version ".$php5;
$result = version_compare(PHP_VERSION,$php5);
if($result == 0){
echo "\nversions are equal";
} else {
echo "\nversion used for .php5 is ".(($result==-1)?'higher':'lower');
}
}
--------------------

Thanks for the information.
Feb 16 '07 #7

P: n/a
"Kimmo Laine" <sp**@outolempi.netwrote in message
news:er**********@nyytiset.pp.htv.fi...
McKirahan kirjoitti:
"McKirahan" <Ne**@McKirahan.comwrote in message
news:dO******************************@comcast.com. ..
I am working in two environments neither configuration of
which I can change; one's my Web host the other a client.

My Web host requires the use of the ".php5" extension
to use PHP v5.1.4; where ".php" is used for PHP v4.3.11.
My client supports PHP v5.2.0 with the ".php" extension.

Is there a way to reliably determine if the ".php5" extension
must be used on a server? Perhaps via a "phpinfo()" value?

I have a page that uses the v5 function "file_put_contents()".
(I like it's LOCK_EX feature.)

Thanks in advance.

I tried this (to not write to the file in the function isn't supported):

try {
file_put_contents($file, $text, FILE_APPEND+LOCK_EX);
} catch (Exception $e) {
echo "Caught exception: ", $e->getMessage(), "\n";
}

but got this error:

Parse error: parse error, unexpected '{' ...

It doesn't like my use of "try - catch".
Why isn't "try - catch" documented?
I found only one reference; (under "Exceptions").

Don't know if these help you any but two observations:

1) you can get the version of php with phpversion();
http://fi.php.net/manual/en/function.phpversion.php

2) You can test wether a function exists with

if(function_exists('file_put_contents')){
file_put_contents($file, $text, FILE_APPEND+LOCK_EX);
} else {
echo "craptastic!";
}
Thanks! I'm going to use "function_exists()".
Feb 16 '07 #8

P: n/a
"shimmyshack" <ma********@gmail.comwrote in message
news:11**********************@a34g2000cwb.googlegr oups.com...
On Feb 15, 6:05 pm, Kimmo Laine <s...@outolempi.netwrote:

[snip]
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
s...@outolempi.net | Gedoon-S @ IRCnet | rot13(x...@bhgbyrzcv.arg)
oh and of course, dont forget the other typo ,->. further on the same
line!!
Please notify the PHP Documentation Group; here's their example:

Chapter 20. Exceptions

Example 20-1. Throwing an Exception

<?php
try {
$error = 'Always throw this error';
throw new Exception($error);

// Code following an exception is not executed.
echo 'Never executed';

} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}

// Continue execution
echo 'Hello World';
?>

Feb 16 '07 #9

P: n/a
Rik
On Fri, 16 Feb 2007 02:48:06 +0100, McKirahan <Ne**@McKirahan.comwrote:
Thanks! I'm going to use "function_exists()".
Don't forget PEAR PHP_Compat, saves a lot of headaches in trying to write
your own workarounds...
--
Rik Wasmus
Feb 16 '07 #10

P: n/a
"McKirahan" <Ne**@McKirahan.comwrote in message
news:Fc******************************@comcast.com. ..
"shimmyshack" <ma********@gmail.comwrote in message
news:11**********************@a34g2000cwb.googlegr oups.com...
On Feb 15, 6:05 pm, Kimmo Laine <s...@outolempi.netwrote:

[snip]
>"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
s...@outolempi.net | Gedoon-S @ IRCnet | rot13(x...@bhgbyrzcv.arg)

oh and of course, dont forget the other typo ,->. further on the same
line!!
Please notify the PHP Documentation Group; here's their example:

Chapter 20. Exceptions

Example 20-1. Throwing an Exception

<?php
try {
$error = 'Always throw this error';
throw new Exception($error);

// Code following an exception is not executed.
echo 'Never executed';

} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}

The gag here is that when using a dot, you're concatenating two strings,
when using a comma your passing two (or more) arguments to echo, so the
comma thing only works with echo which is capable of recieveing arbitrary
number of parameters, unlike print for example. Thus print('foo','bar')
doesn't work while echo('foo','bar') does. Actually it might save just a
teeny bit of cpu cycles if the strings aren't concatenated but instead
passed as separate parameters. Go figure. For the sake of readability, using
dots consistently might be wise.

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net | rot13(xv***@bhgbyrzcv.arg)
Feb 16 '07 #11

P: n/a
"Rik" <lu************@hotmail.comwrote in message
news:op.tnto7jx2qnv3q9@misant...
On Fri, 16 Feb 2007 02:48:06 +0100, McKirahan <Ne**@McKirahan.comwrote:
Thanks! I'm going to use "function_exists()".

Don't forget PEAR PHP_Compat, saves a lot of headaches in trying to write
your own workarounds...
--
Rik Wasmus
I'm rather new to PHP (though I know JS and VBS);
how can I determine if PEAR is installed on the Web server?
Feb 16 '07 #12

P: n/a
On Feb 16, 6:37 am, "Kimmo Laine" <s...@outolempi.netwrote:
"McKirahan" <N...@McKirahan.comwrote in message

news:Fc******************************@comcast.com. ..
"shimmyshack" <matt.fa...@gmail.comwrote in message
news:11**********************@a34g2000cwb.googlegr oups.com...
On Feb 15, 6:05 pm, Kimmo Laine <s...@outolempi.netwrote:
[snip]
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
s...@outolempi.net | Gedoon-S @ IRCnet | rot13(x...@bhgbyrzcv.arg)
oh and of course, dont forget the other typo ,->. further on the same
line!!
Please notify the PHP Documentation Group; here's their example:
Chapter 20. Exceptions
Example 20-1. Throwing an Exception
<?php
try {
$error = 'Always throw this error';
throw new Exception($error);
// Code following an exception is not executed.
echo 'Never executed';
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}

The gag here is that when using a dot, you're concatenating two strings,
when using a comma your passing two (or more) arguments to echo, so the
comma thing only works with echo which is capable of recieveing arbitrary
number of parameters, unlike print for example. Thus print('foo','bar')
doesn't work while echo('foo','bar') does. Actually it might save just a
teeny bit of cpu cycles if the strings aren't concatenated but instead
passed as separate parameters. Go figure. For the sake of readability, using
dots consistently might be wise.

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpkhttp://outolempi.net/ahdistus/- Satunnaisesti päivittyvä nettisarjis
s...@outolempi.net | rot13(x...@bhgbyrzcv.arg)
yeah, do you know in years of php programming I've only ever
concatenated strings when using echo - my bad - although I always use
' instead of " so brownie points there huh! perhaps its time to go
read up on some other functions too! sorry for any confusion, I don't
think ill be notifying the php doc group!

Feb 17 '07 #13

P: n/a
Rik
On Sat, 17 Feb 2007 00:54:36 +0100, shimmyshack <ma********@gmail.com>
wrote:
yeah, do you know in years of php programming I've only ever
concatenated strings when using echo - my bad - although I always use
' instead of " so brownie points there huh! perhaps its time to go
read up on some other functions too! sorry for any confusion, I don't
think ill be notifying the php doc group!
echo is not a function, it's a construct :P
Hence the unexpecyed behaviour.
--
Rik Wasmus
Feb 17 '07 #14

P: n/a
Rik
McKirahan <Ne**@McKirahan.comwrote:
I'm rather new to PHP (though I know JS and VBS);
how can I determine if PEAR is installed on the Web server?
All coding issues aside: easiest and fastest way is just to ask you hoster.
--
Rik Wasmus
Feb 17 '07 #15

P: n/a
Rik
Hmmmz, anyone else getting this twice? Seeems to be a trouble with Opera
newsgrouphandling, but I'm not sure.....

--
Rik Wasmus

Thinking that after a long satisfying trial of Opera it may very well be
it's got some irreconcilable flaw
Feb 17 '07 #16

P: n/a
Rik wrote:
Hmmmz, anyone else getting this twice? Seeems to be a trouble with Opera
newsgrouphandling, but I'm not sure.....

--Rik Wasmus

Thinking that after a long satisfying trial of Opera it may very well be
it's got some irreconcilable flaw
I don't recall any problems like that while using Opera. However, I've
been sticking with Thunderbird, lately.

--
Curtis
Feb 17 '07 #17

P: n/a
McKirahan wrote:
I am working in two environments neither configuration of
which I can change; one's my Web host the other a client.

My Web host requires the use of the ".php5" extension
to use PHP v5.1.4; where ".php" is used for PHP v4.3.11.
My client supports PHP v5.2.0 with the ".php" extension.

Is there a way to reliably determine if the ".php5" extension
must be used on a server? Perhaps via a "phpinfo()" value?

I have a page that uses the v5 function "file_put_contents()".
(I like it's LOCK_EX feature.)

Thanks in advance.

What's wrong with coding your own version of file_put_contents? The
cool thing about the user notes on php.net's docs, is that if there
are any backward compatibility issues, users will usually post
workaround functions. Over time, they generally get more efficient, as
one person tries to do the same thing more efficiently than the last.
The user notes aren't validated though, so you need to have your wits
about you when it comes to making sure code won't become a security risk.

--
Curtis
Feb 17 '07 #18

P: n/a
Rik kirjoitti:
On Sat, 17 Feb 2007 00:54:36 +0100, shimmyshack <ma********@gmail.com>
wrote:
>yeah, do you know in years of php programming I've only ever
concatenated strings when using echo - my bad - although I always use
' instead of " so brownie points there huh! perhaps its time to go
read up on some other functions too! sorry for any confusion, I don't
think ill be notifying the php doc group!

echo is not a function, it's a construct :P
Hence the unexpecyed behaviour.
--Rik Wasmus
Normal functions are also capable of recieveing an arbitrary number of
parameters. Print just isn't programmed to handle them. It's true that
echo is a language construct, but that doesn't make it magical.

Something like this should work: (didn't test thou)

function print_multiple(){
foreach(func_get_args() as $arg)
print($arg);
}

print_multiple('Hello', ' ', 'world!'); // Using commas instead of dots.

--
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)
Feb 17 '07 #19

P: n/a
Rik
On Sat, 17 Feb 2007 14:41:08 +0100, Kimmo Laine <sp**@outolempi.netwrote:
Rik kirjoitti:
>On Sat, 17 Feb 2007 00:54:36 +0100, shimmyshack <ma********@gmail.com>
wrote:
>>yeah, do you know in years of php programming I've only ever
concatenated strings when using echo - my bad - although I always use
' instead of " so brownie points there huh! perhaps its time to go
read up on some other functions too! sorry for any confusion, I don't
think ill be notifying the php doc group!
echo is not a function, it's a construct :P
Hence the unexpecyed behaviour.
--Rik Wasmus

Normal functions are also capable of recieveing an arbitrary number of
parameters. Print just isn't programmed to handle them. It's true that
echo is a language construct, but that doesn't make it magical.
Indeed you are right, I was talking out of my ass. Being a construct has
nothing to do with it (other then you don't need brackets). Why the hell
do I feel the need to post at 5 o'clock at night after a party?
--
Rik Wasmus
Feb 17 '07 #20

This discussion thread is closed

Replies have been disabled for this discussion.