FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Strange: echo() vs. echo





imagefree
Just observed for the first time.

Code:
echo ( 'ABC' , 'ABC' );

Gives Parse error. While the below does not.

Code:
echo 'ABC' , 'ABC';
jmraker
I did not know this either, here's more info on the subject

http://www.electrictoolbox.com/php-echo-commas-vs-concatenation/
http://wolfprojects.altervista.org/outputinphp.php

If you wanted you could write a function that could echo strings and values seperated with commas if you used func_get_args() or func_get_arg() and func_num_args()
http://us.php.net/manual/en/function.func-get-args.php
rvec
Quote:
echo() is not actually a function (it is a language construct), so you are not required to use parentheses with it. echo() (unlike some other language constructs) does not behave like a function, so it cannot always be used in the context of a function. Additionally, if you want to pass more than one parameter to echo(), the parameters must not be enclosed within parentheses.

http://php.net/manual/en/function.echo.php

That´s why it isn´t allowed.

Code:
function echo() {
  echo explode('', func_get_args());
}


This would act like echo, but would be used as a function (I wouldn't know when you could use it, but because it was mentioned by jmraker...). Just like echo it would be able to return strings and numbers, and would return 'Array' when an array is given as an argument.
rickylau
rvec wrote:

Code:
function echo() {
  echo explode('', func_get_args());
}
explode? you mean implode right?
rvec
rickylau wrote:
rvec wrote:

Code:
function echo() {
  echo explode('', func_get_args());
}
explode? you mean implode right?

Oops , yeah I meant implode. Was working with explodes just before I wrote that, must've mixed them up.
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.