[PHP] Carriage Return problem!
Hi, I am using php to generate and xml output file from another xml file using xsl. The file is getting created properly and the xml instruction element is at 1st line. I am using ant to get the output remotely but it is adding one extra line i.e. carriage return. I checked everything in my xsl, tried xsl:strip-space, no indent etc but as i said file is properly created. I have checked my echo's and print statments but there is none. If somebody has tried to direct the output of browser through ant (or some other tool) and came across the same situation and tackled it please inform me. Does the php interpreter enters a carriage return by default as i tried to remome the xml contents and print one normal line of output it still gave me carriage return in the first line. Any help will be highly appreciated. Thanks!
Re: [PHP] Carriage Return problem!
Make sure there are no extra characters (including linefeeds) after the closing ? in your php source file. Brandon Ryan On 12 Apr 2005 19:42:17 -, Dipesh Khakhkhar [EMAIL PROTECTED] wrote: Hi, I am using php to generate and xml output file from another xml file using xsl. The file is getting created properly and the xml instruction element is at 1st line. I am using ant to get the output remotely but it is adding one extra line i.e. carriage return. I checked everything in my xsl, tried xsl:strip-space, no indent etc but as i said file is properly created. I have checked my echo's and print statments but there is none. If somebody has tried to direct the output of browser through ant (or some other tool) and came across the same situation and tackled it please inform me. Does the php interpreter enters a carriage return by default as i tried to remome the xml contents and print one normal line of output it still gave me carriage return in the first line. Any help will be highly appreciated. Thanks!
RE: [PHP] or return problem
On 08 October 2003 17:20, Chris Shiflett wrote: The internals developers probably didn't see a need to provide support for return in conditionals since it can't return a value to the conditional. Ugh. This is the same misconception, again. Let's try some different code: ? function foo() { echo foo\n; } function bar() { return true; } bar() or foo(); The return of foo() does not matter. It is not evaluated. Semantically, that is true -- but syntactically it still has to *have* a potential value (since bar() *might* return false), so PHP will barf at the compilation stage if instead of foo() you have a construct which *cannot* return a value. The distinction is not whether the construct on the right of or is actually executed or not for any given combination of input values, but whether it is *capable* of returning a value, should it be called upon to do so. I do not understand why this is still unclear. Consider this: if (!bar()) { foo(); } Does it seem like foo() is involved in the conditional when expressed like this? I hope not. No -- but expressed like this, foo() is not required to have a return value -- it only needs to be executable. In bar() or foo() it must actually be *capable* of returning a value, even if that value can never be used. In short, it's a compile-time question (can this construct return a value if required to do so?) vs a run-time question (does this construct need to be evaluated?). Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] or return problem
On 07 October 2003 18:15, Pat Carmody contributed these pearls of wisdom: So far everyone is telling me that it won't work, but no one is telling me why. (btw I did search extensively for the answer to this question but so far have found nothing). Robert, could you be more specific in your reference to the http://www.php.net documentation? I see nothing on the basic syntax page that addresses this. Pat Carmody On Tue, 7 Oct 2003, Robert Cummings wrote: On Tue, 2003-10-07 at 13:02, Pat Carmody wrote: Calling the following retor_test() function causes a Parse error: parse error, unexpected T_RETURN message when the script is run: function istrue() { return true; } function retor_test() { istrue() or return( False ); return True; } The problem is with the or return part. Any ideas why? I realize that I could use an if statement instead, but I'm a lazy, lazy man and I don't want to. Well, let's see if I can contribute something useful here. Firstly, or, as a Boolean operator requires two operands, both of which must have an actual value. Now, according to the manual (at http://www.php.net/manual/en/functions.returning-values.php), Values are returned [from a function] by using the optional return statement -- so return is a statement, and statements don't have a value (and can't even be coerced to have one), so return can't be valid as one of the operands to or. On the other hand, exit (and its alias die) are function-like language constructs which do have a value, even if it's only NULL produced by coercing a void return, so they are valid as an operand to or. (Of course, you can never make use of the NULL return from exit or die, because your script will already have exited or died before it gets the opportunity to do so -- but the very fact that they are language constructs with a potential return value means they can be used in a context which demands a value, where return, which doesn't have a value, can't!) Hope that's all a bit clearer than mud ;) Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] or return problem
--- Ford, Mike [LSS] [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Firstly, or, as a Boolean operator requires two operands, both of which must have an actual value. [snip] statements don't have a value (and can't even be coerced to have one), so return can't be valid as one of the operands to or. Based on yesterday's discussion, this seems to be a very common misconception. I will try to clear it up. Let's take a common use: mysql_query($sql) or die(mysql_error()); There is a conditional here, but it has nothing to do with the die() part. The or is not the same as || in a conditional expression. The return of die() is not being evaluated. Only the return of mysql_query() is. This can be rewritten as follows: if (!mysql_query($sql)) { die(mysql_error()); } If it helps, you can possibly replace or with else when you read these types of statements to clarify the use. It makes sense to me like it is. This really just boils down to language semantics, and it probably makes more sense to native English speakers than others. The word or means different things in the following two examples: 1. If you find some Coke or Pepsi, buy some. This suggests that either Coke or Pepsi will suffice. In PHP: if ($type == 'coke' || $type == 'pepsi') { buy_some(); } 2. Bring me the antidote, or I will die. This suggests that if the antidote is not brought, the speaker will die. If it is, the or I will die part never happens. In PHP: bring_antidote() or die; Of course, die is just an alias for exit, but it sounds better. :-) Hope that helps. Chris = My Blog http://shiflett.org/ HTTP Developer's Handbook http://httphandbook.org/ RAMP Training Courses http://www.nyphp.org/ramp -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] or return problem
* Thus wrote Chris Shiflett ([EMAIL PROTECTED]): --- Ford, Mike [LSS] [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Firstly, or, as a Boolean operator requires two operands, both of which must have an actual value. [snip] statements don't have a value (and can't even be coerced to have one), so return can't be valid as one of the operands to or. Based on yesterday's discussion, this seems to be a very common misconception. I will try to clear it up. To add this, the 'include' family also accepts this construct: condition or include(file); Which also violates the rule that statments (constructs) dont have return values. I have a feeling die() was special cased to inherit the popular perl method of using: condition or die(); 1. If you find some Coke or Pepsi, buy some. This suggests that either Coke or Pepsi will suffice. In PHP: if ($type == 'coke' || $type == 'pepsi') { buy_some(); } So now we're at $coke or $pepsi and buy_some() :) Curt -- My PHP key is worn out PHP List stats since 1997: http://zirzow.dyndns.org/html/mlists/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] or return problem
On Wed, 2003-10-08 at 11:43, Curt Zirzow wrote: * Thus wrote Chris Shiflett ([EMAIL PROTECTED]): --- Ford, Mike [LSS] [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Firstly, or, as a Boolean operator requires two operands, both of which must have an actual value. [snip] statements don't have a value (and can't even be coerced to have one), so return can't be valid as one of the operands to or. Based on yesterday's discussion, this seems to be a very common misconception. I will try to clear it up. To add this, the 'include' family also accepts this construct: condition or include(file); Which also violates the rule that statments (constructs) dont have return values. This isn't a rule per se since it really depends on whether special treatment was given to the construct. The internals developers probably didn't see a need to provide support for return in conditionals since it can't return a value to the conditional. Incidentally does return in this manner work in perl since it appears that's what the or die() stuff is attmepting to mimic. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] or return problem
* Thus wrote Robert Cummings ([EMAIL PROTECTED]): On Wed, 2003-10-08 at 11:43, Curt Zirzow wrote: * Thus wrote Chris Shiflett ([EMAIL PROTECTED]): --- Ford, Mike [LSS] [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Firstly, or, as a Boolean operator requires two operands, both of which must have an actual value. [snip] statements don't have a value (and can't even be coerced to have one), so return can't be valid as one of the operands to or. Based on yesterday's discussion, this seems to be a very common misconception. I will try to clear it up. To add this, the 'include' family also accepts this construct: condition or include(file); Which also violates the rule that statments (constructs) dont have return values. This isn't a rule per se since it really depends on whether special treatment was given to the construct. The internals developers probably didn't see a need to provide support for return in conditionals since it can't return a value to the conditional. Incidentally does return in this manner work in perl since it appears that's what the or die() stuff is attmepting to mimic. perl: 0 or return; Works fine. Curt -- My PHP key is worn out PHP List stats since 1997: http://zirzow.dyndns.org/html/mlists/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] or return problem
On 08 October 2003 16:13, Chris Shiflett contributed these pearls of wisdom: --- Ford, Mike [LSS] [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Firstly, or, as a Boolean operator requires two operands, both of which must have an actual value. [snip] statements don't have a value (and can't even be coerced to have one), so return can't be valid as one of the operands to or. Based on yesterday's discussion, this seems to be a very common misconception. No, it's not -- the misconception appears to be yours. I will try to clear it up. And I will try to clear up your clearing up. Let's take a common use: mysql_query($sql) or die(mysql_error()); There is a conditional here, but it has nothing to do with the die() part. The or is not the same as || in a conditional expression. Only because it's got a different precedence -- in all other respects, || and or are identical (Boolean-or operator with lazy, or short-circuit, evaluation). The return of die() is not being evaluated. That's because of the lazy evaluation of Boolean operators in PHP, nothing to do with whether it's or or ||. Only the return of mysql_query() is. This can be rewritten as follows: if (!mysql_query($sql)) { die(mysql_error()); } If it helps, you can possibly replace or with else when you read these types of statements to clarify the use. It makes sense to me like it is. This really just boils down to language semantics, and it probably makes more sense to native English speakers than others. The word or means different things in the following two examples: 1. If you find some Coke or Pepsi, buy some. This suggests that either Coke or Pepsi will suffice. In PHP: if ($type == 'coke' || $type == 'pepsi') OR: if ($type == 'coke' or $type == 'pepsi') (Note that lazy evaluation applies in this case as well -- if $type is, in fact, == 'coke', the $type == 'pepsi' condition will never be evaluated.) { buy_some(); } 2. Bring me the antidote, or I will die. This suggests that if the antidote is not brought, the speaker will die. If it is, the or I will die part never happens. In PHP: bring_antidote() or die; OR: bring_antidote() || die; There really is no difference between the or and || operators apart from their precedence (see, for example, http://uk.php.net/manual/en/language.operators.php#language.operators.preced ence and http://uk.php.net/manual/en/language.operators.logical.php), and because of their ordering in relation to other operators it's really only in combination with assignment operators that they can cause problems. For example, consider the following: $y = validate($x) or print Invalid!; This is evaluated as ($y = validate($x)) or print Invalid!; which is probably what was intended -- $y is assigned the the value of validate($x), and then the print is only executed if that is false. However: $y = validate($x) || print Invalid!; is evaluated as: $y = (validate($x) || print Invalid!); which will assign to $y the value of validate($x) if it is non-empty, otherwise will execute the print and assign 1 (the return value of print) to $y. This is probably not what the writer intended. Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] or return problem
On 08 October 2003 16:43, Robert Cummings contributed these pearls of wisdom: On Wed, 2003-10-08 at 11:43, Curt Zirzow wrote: * Thus wrote Chris Shiflett ([EMAIL PROTECTED]): --- Ford, Mike [LSS] [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Firstly, or, as a Boolean operator requires two operands, both of which must have an actual value. [snip] statements don't have a value (and can't even be coerced to have one), so return can't be valid as one of the operands to or. Based on yesterday's discussion, this seems to be a very common misconception. I will try to clear it up. To add this, the 'include' family also accepts this construct: condition or include(file); Which also violates the rule that statments (constructs) dont have return values. Well, include isn't really just a statement, since You can take the value of the include call as you would a normal function. (from http://uk.php.net/manual/en/function.include.php). Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] or return problem
The internals developers probably didn't see a need to provide support for return in conditionals since it can't return a value to the conditional. Ugh. This is the same misconception, again. Let's try some different code: ? function foo() { echo foo\n; } function bar() { return true; } bar() or foo(); ? The return of foo() does not matter. It is not evaluated. I do not understand why this is still unclear. Consider this: if (!bar()) { foo(); } Does it seem like foo() is involved in the conditional when expressed like this? I hope not. Chris = My Blog http://shiflett.org/ HTTP Developer's Handbook http://httphandbook.org/ RAMP Training Courses http://www.nyphp.org/ramp -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] or return problem
--- Ford, Mike [LSS] [EMAIL PROTECTED] wrote: No, it's not -- the misconception appears to be yours. Well, perhaps it is a difference in perspective. Yes, or and || can be exchanged: 1. if ($foo or $bar) blah(); 2. mysql_query($sql) || die(mysql_error()); My point was to differentiate the two examples above, regardless of format. A conditional means to me that there is a fork in the path. In example 1 above, the fork is whether blah() is to be executed or not, and what determines that is whether either $foo or $bar evaluate as true. In example 2, the fork is whether die(mysql_error()) happens, and what determines that is whether mysql_query($sql) evaluates as true (indicating the query was successful). I guess you could see two different forks in the path concerning example 1, because $bar is only evaluated if $foo is false. Either way, the primary point of the conditional expression is to determine whether blah() should be executed. So, you are right, but I think of things a bit differently. Chris = My Blog http://shiflett.org/ HTTP Developer's Handbook http://httphandbook.org/ RAMP Training Courses http://www.nyphp.org/ramp -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] or return problem
Calling the following retor_test() function causes a Parse error: parse error, unexpected T_RETURN message when the script is run: function istrue() { return true; } function retor_test() { istrue() or return( False ); return True; } The problem is with the or return part. Any ideas why? I realize that I could use an if statement instead, but I'm a lazy, lazy man and I don't want to. Pat Carmody -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] or return problem
On Tue, 2003-10-07 at 13:02, Pat Carmody wrote: Calling the following retor_test() function causes a Parse error: parse error, unexpected T_RETURN message when the script is run: function istrue() { return true; } function retor_test() { istrue() or return( False ); return True; } The problem is with the or return part. Any ideas why? I realize that I could use an if statement instead, but I'm a lazy, lazy man and I don't want to. Your laziness is causing you problems. Please check out ALL of the documenation located at http://www.php.net since this is covered under basic syntax and we don't cater to lazy people (at the very least *I* don't cater to lazy people). Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] or return problem
Well Unfortunately pat You are going to have to be an unlazy man and use an if statement Chris Calling the following retor_test() function causes a Parse error: parse error, unexpected T_RETURN message when the script is run: function istrue() { return true; } function retor_test() { istrue() or return( False ); return True; } The problem is with the or return part. Any ideas why? I realize that I could use an if statement instead, but I'm a lazy, lazy man and I don't want to. Pat Carmody -- 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] or return problem
Incidentally your post probably caused you more work than to have tested it yourself. So much for your laziness even being optimal laziness. *pt*. I thought making stupid posts was covered in the newbie guide!?! Rob. On Tue, 2003-10-07 at 13:06, Robert Cummings wrote: On Tue, 2003-10-07 at 13:02, Pat Carmody wrote: Calling the following retor_test() function causes a Parse error: parse error, unexpected T_RETURN message when the script is run: function istrue() { return true; } function retor_test() { istrue() or return( False ); return True; } The problem is with the or return part. Any ideas why? I realize that I could use an if statement instead, but I'm a lazy, lazy man and I don't want to. Your laziness is causing you problems. Please check out ALL of the documenation located at http://www.php.net since this is covered under basic syntax and we don't cater to lazy people (at the very least *I* don't cater to lazy people). Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] or return problem
So far everyone is telling me that it won't work, but no one is telling me why. (btw I did search extensively for the answer to this question but so far have found nothing). Robert, could you be more specific in your reference to the http://www.php.net documentation? I see nothing on the basic syntax page that addresses this. Pat Carmody On Tue, 7 Oct 2003, Robert Cummings wrote: On Tue, 2003-10-07 at 13:02, Pat Carmody wrote: Calling the following retor_test() function causes a Parse error: parse error, unexpected T_RETURN message when the script is run: function istrue() { return true; } function retor_test() { istrue() or return( False ); return True; } The problem is with the or return part. Any ideas why? I realize that I could use an if statement instead, but I'm a lazy, lazy man and I don't want to. Your laziness is causing you problems. Please check out ALL of the documenation located at http://www.php.net since this is covered under basic syntax and we don't cater to lazy people (at the very least *I* don't cater to lazy people). Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- 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] or return problem
I already said Your laziness is causing you problems, this refers back to your original statement about being lazy. You should be able to infer form your own wrods the root of your problem. Rob. On Tue, 2003-10-07 at 13:14, Pat Carmody wrote: So far everyone is telling me that it won't work, but no one is telling me why. (btw I did search extensively for the answer to this question but so far have found nothing). Robert, could you be more specific in your reference to the http://www.php.net documentation? I see nothing on the basic syntax page that addresses this. Pat Carmody On Tue, 7 Oct 2003, Robert Cummings wrote: On Tue, 2003-10-07 at 13:02, Pat Carmody wrote: Calling the following retor_test() function causes a Parse error: parse error, unexpected T_RETURN message when the script is run: function istrue() { return true; } function retor_test() { istrue() or return( False ); return True; } The problem is with the or return part. Any ideas why? I realize that I could use an if statement instead, but I'm a lazy, lazy man and I don't want to. Your laziness is causing you problems. Please check out ALL of the documenation located at http://www.php.net since this is covered under basic syntax and we don't cater to lazy people (at the very least *I* don't cater to lazy people). Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] or return problem
On Tue, Oct 07, 2003 at 01:02:36PM -0400, Pat Carmody wrote: : : Calling the following retor_test() function causes a Parse error: parse : error, unexpected T_RETURN message when the script is run: : : function istrue() { : return true; : } : function retor_test() { : istrue() or return( False ); : return True; : } : : The problem is with the or return part. Any ideas why? Yes. : I realize that I could use an if statement instead, You just answered your own question. : but I'm a lazy, lazy man and I don't want to. Just use an if statement. Lazy, Perl-ish syntax blows chunks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] or return problem
Chris Sherwood wrote: Well Unfortunately pat You are going to have to be an unlazy man and use an if statement Why won't any of you give a good reason why it won't work? How come this works: function foo() { 2+2==4 or die(The world is ending, or at least your processor!); } But this doesn't: function foo() { 2+2==4 or return(The world is ending, or at least your processor!); } The way I see it, there's something really odd going on here. -- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] or return problem
Why won't any of you give a good reason why it won't work? How come this works: function foo() { 2+2==4 or die(The world is ending, or at least your processor!); } But this doesn't: function foo() { 2+2==4 or return(The world is ending, or at least your processor!); } The way I see it, there's something really odd going on here. Directly from the docs: http://ca3.php.net/manual/en/function.return.php First line: If called from within a function, the return() statement immediately ends execution of the current function Important concept: IMMEDIATELY returns. Learn to read. Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] or return problem
Robert Cummings wrote: Directly from the docs: http://ca3.php.net/manual/en/function.return.php First line: If called from within a function, the return() statement immediately ends execution of the current function Important concept: IMMEDIATELY returns. Learn to read. What does that have to do with anything? -- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] or return problem
On Tue, 2003-10-07 at 14:29, Leif K-Brooks wrote: Robert Cummings wrote: Directly from the docs: http://ca3.php.net/manual/en/function.return.php First line: If called from within a function, the return() statement immediately ends execution of the current function Important concept: IMMEDIATELY returns. Learn to read. What does that have to do with anything? How can you possibly test, in a conditional, the return value of the return statement itself when it has no value to return and even causes the current scope to exit IMMEDIATELY?? Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] or return problem
Robert Cummings wrote: How can you possibly test, in a conditional, the return value of the return statement itself when it has no value to return and even causes the current scope to exit IMMEDIATELY?? Ok, that explains it. Thanks. -- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] or return problem
How can you possibly test, in a conditional, the return value of the return statement itself when it has no value to return and even causes the current scope to exit IMMEDIATELY?? Per the logic, if it returns immediately, isn't the value irrelevant? That is, assuming that the truth of the first clause short-circuits evaluation of the second one. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] or return problem
On Tue, 2003-10-07 at 14:40, Roger B.A. Klorese wrote: How can you possibly test, in a conditional, the return value of the return statement itself when it has no value to return and even causes the current scope to exit IMMEDIATELY?? Per the logic, if it returns immediately, isn't the value irrelevant? That is, assuming that the truth of the first clause short-circuits evaluation of the second one. Depends on how the return statement is processed since it obviously has special treatment. But yes, that would be a bug probably if indeed the the return expression should never be evaluated due to the left operand evaluating to true. Nonetheless, it's a dirty style for a return IMHO since if the left operand does evaluate to false then the conditional is undefined as far as I can tell. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] or return problem
--- Robert Cummings [EMAIL PROTECTED] wrote: Directly from the docs: http://ca3.php.net/manual/en/function.return.php First line: If called from within a function, the return() statement immediately ends execution of the current function Important concept: IMMEDIATELY returns. Learn to read. What does that have to do with anything? How can you possibly test, in a conditional, the return value of the return statement itself when it has no value to return and even causes the current scope to exit IMMEDIATELY?? The code in question, I believe, was basically this: function foo() { true or return('foo'); } Your answer does not address the question as to why this is invalid syntax, but instead you explain how return works. This is what Leif is questioning, I believe. Regardless, a little less hostility would be nice. Chris = My Blog http://shiflett.org/ HTTP Developer's Handbook http://httphandbook.org/ RAMP Training Courses http://www.nyphp.org/ramp -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] or return problem
On Tue, 2003-10-07 at 14:45, Chris Shiflett wrote: --- Robert Cummings [EMAIL PROTECTED] wrote: Directly from the docs: http://ca3.php.net/manual/en/function.return.php First line: If called from within a function, the return() statement immediately ends execution of the current function Important concept: IMMEDIATELY returns. Learn to read. What does that have to do with anything? How can you possibly test, in a conditional, the return value of the return statement itself when it has no value to return and even causes the current scope to exit IMMEDIATELY?? The code in question, I believe, was basically this: function foo() { true or return('foo'); } Your answer does not address the question as to why this is invalid syntax, but instead you explain how return works. This is what Leif is questioning, I believe. Regardless, a little less hostility would be nice. The original post came from someone being lazy, that appears to be influencing my take on the thread :) Also given the above code, it's completely pointless since the first operand is true and so it is impossible for return( 'foo' ) to ever be evaluated (and as stated in a post just before this the expression shouldn't break). Nonetheless given a variable as the first operand, I think anyone coding a return in a conditional like that is asking for trouble since I would guess that it has an undefined return value. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] or return problem
On Wednesday 08 October 2003 02:51, Robert Cummings wrote: The original post came from someone being lazy, that appears to be influencing my take on the thread :) Also given the above code, it's completely pointless since the first operand is true and so it is impossible for return( 'foo' ) to ever be evaluated (and as stated in a post just before this the expression shouldn't break). Nonetheless given a variable as the first operand, I think anyone coding a return in a conditional like that is asking for trouble since I would guess that it has an undefined return value. The example given by Leif does not even run. You get a parse error. So all the discussion about return exiting immediately and the left expression evaluating to whatever is (IMHO) moot. Apparently PHP does not allow you to use return like that, period. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* Wernher von Braun settled for a V-2 when he coulda had a V-8. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] or return problem
On Tue, 2003-10-07 at 14:51, Robert Cummings wrote: The original post came from someone being lazy, that appears to be influencing my take on the thread :) Also given the above code, it's completely pointless since the first operand is true and so it is impossible for return( 'foo' ) to ever be evaluated (and as stated in a post just before this the expression shouldn't break). Nonetheless given a variable as the first operand, I think anyone coding a return in a conditional like that is asking for trouble since I would guess that it has an undefined return value. I would say the real issue at hand here is that the return statement is not a fucntion, but rather a language construct, thus it cannot be used as a function unless explicitly stated as so. The reason a parse error is occurring is because this particular construct has no support for being used in the given context. It would be like dropping in any other language construct suddenly such as a { or @ where it is not understood. Given that die() and exit() works just means they have been given support for this context. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] or return problem
On Tue, 2003-10-07 at 15:00, Jason Wong wrote: The example given by Leif does not even run. You get a parse error. So all the discussion about return exiting immediately and the left expression evaluating to whatever is (IMHO) moot. Apparently PHP does not allow you to use return like that, period. Yep. Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] or return problem
--- Robert Cummings [EMAIL PROTECTED] wrote: The original post came from someone being lazy, that appears to be influencing my take on the thread :) Understandable. :-) Also given the above code, it's completely pointless since the first operand is true and so it is impossible for return( 'foo' ) to ever be evaluated I don't think that was the point. You can rewrite it like this if you like: function foo() { false or return 'foo'; } I believe the original poster mentioned being lazy to justify why this code is not used instead: function foo() { if (!false) { return 'foo'; } } The conditional expression itself is irrelevant. This is a question about the language construct. I think anyone coding a return in a conditional like that is asking for trouble since I would guess that it has an undefined return value. Well, anyone who tries that code will get a parse error, so that is definitely an invitation for trouble. The return value would be defined if this worked as I think it the original poster indended. The 'or' is not a typical conditional statement, by the way, otherwise this would work just fine. Hope that helps. Chris = My Blog http://shiflett.org/ HTTP Developer's Handbook http://httphandbook.org/ RAMP Training Courses http://www.nyphp.org/ramp -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] or return problem
I would say the real issue at hand here is that the return statement is not a fucntion, but rather a language construct, thus it cannot be used as a function unless explicitly stated as so. The reason a parse error is occurring is because this particular construct has no support for being used in the given context. It would be like dropping in any other language construct suddenly such as a { or @ where it is not understood. Given that die() and exit() works just means they have been given support for this context. Sounds to me that if it looks like a function, quacks like a function, etc., only a broken language definition would treat it differently from a function... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] or return problem
--- Robert Cummings [EMAIL PROTECTED] wrote: Given that die() and exit() works just means they have been given support for this context. I think you now understand the original poster's question. From my interpretation, he simply wanted to know why return was not given the same support. :-) Chris = My Blog http://shiflett.org/ HTTP Developer's Handbook http://httphandbook.org/ RAMP Training Courses http://www.nyphp.org/ramp -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] or return problem
On Tue, 2003-10-07 at 15:05, Roger B.A. Klorese wrote: Sounds to me that if it looks like a function, quacks like a function, etc., only a broken language definition would treat it differently from a function... Generally it doesn't look like a function since you can do: return 'foo' which has no parenthesis. The parenthesis are optional and only used to return the result of an expression. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] or return problem
On Tue, 2003-10-07 at 15:08, Chris Shiflett wrote: --- Robert Cummings [EMAIL PROTECTED] wrote: Given that die() and exit() works just means they have been given support for this context. I think you now understand the original poster's question. From my interpretation, he simply wanted to know why return was not given the same support. :-) Yep. My bad *bangs head on wall* :) Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] or return problem
Generally it doesn't look like a function since you can do: return 'foo' which has no parenthesis. True enough. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] or return problem
Robert Cummings wrote: Generally it doesn't look like a function since you can do: return 'foo' which has no parenthesis. The parenthesis are optional and only used to return the result of an expression. The same is true of exit/die. -- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] or return problem
--- Leif K-Brooks [EMAIL PROTECTED] wrote: The same is true of exit/die. Right, Robert mentioned this earlier. :-) So, in summation, someone asked why return wasn't given the same support as exit (of which die is an alias), and a lot of discussion that didn't answer this question followed. :-) I don't know the answer myself, but I assume it could be considered (unless it already has and was decided against). Chris = My Blog http://shiflett.org/ HTTP Developer's Handbook http://httphandbook.org/ RAMP Training Courses http://www.nyphp.org/ramp -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] or return problem
On Tue, 2003-10-07 at 15:35, Leif K-Brooks wrote: Robert Cummings wrote: Generally it doesn't look like a function since you can do: return 'foo' which has no parenthesis. The parenthesis are optional and only used to return the result of an expression. The same is true of exit/die. Yep, which is why I said they must receive special treat ment in the parser to be used as they are. They are also stated as being constructs and not functions in the online documentation. Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] or return problem
* Thus wrote Pat Carmody ([EMAIL PROTECTED]): Calling the following retor_test() function causes a Parse error: parse error, unexpected T_RETURN message when the script is run: function istrue() { return true; } function retor_test() { istrue() or return( False ); return True; } The problem is with the or return part. Any ideas why? I realize that I could use an if statement instead, but I'm a lazy, lazy man and I don't want to. I wouldn't call this lazy, more like sloppy and confusing. return (istrue()? 'True': 'False'); hmm.. less typing, easier to understand and logically readable. Curt -- List Stats: http://zirzow.dyndns.org/html/mlists/php_general/ I used to think I was indecisive, but now I'm not so sure. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] or return problem
--- Curt Zirzow [EMAIL PROTECTED] wrote: I wouldn't call this lazy, more like sloppy and confusing. return (istrue()? 'True': 'False'); hmm.. less typing, easier to understand and logically readable. Well, that is arguable. :-) I'm not a big fan of the ternary operator when it comes to readability. Also, please don't discourage people from posting a concise example that illustrates their question. If you tear apart the logic of their example (and intentionally miss the point of the question), people are encouraged to post huge lists of realistic code. This doesn't really help anyone. Thanks. Chris = My Blog http://shiflett.org/ HTTP Developer's Handbook http://httphandbook.org/ RAMP Training Courses http://www.nyphp.org/ramp -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] or return problem
On Tue, 7 Oct 2003, Curt Zirzow wrote: function istrue() { return true; } function retor_test() { istrue() or return( False ); return True; } return (istrue()? 'True': 'False'); hmm.. less typing, easier to understand and logically readable. This doesn't answer the problem because it does not follow the same logic as the orignial code example. In your example you want to return a value regardless of what istrue() returns. In my example I only wanted to return a value if istrue() failed, otherwise I wanted to continue in the scope of the function. That may not have been obvious because the example was a little contrived. Pat Carmody -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] or return problem
On Tue, 2003-10-07 at 16:53, Pat Carmody wrote: On Tue, 7 Oct 2003, Curt Zirzow wrote: function istrue() { return true; } function retor_test() { istrue() or return( False ); return True; } return (istrue()? 'True': 'False'); hmm.. less typing, easier to understand and logically readable. This doesn't answer the problem because it does not follow the same logic as the orignial code example. In your example you want to return a value regardless of what istrue() returns. In my example I only wanted to return a value if istrue() failed, otherwise I wanted to continue in the scope of the function. That may not have been obvious because the example was a little contrived. here you go: if( 'some condition' ) { return 'some value'; } Simple, logical, exactly the way 99.9% of the population would code what you want. Incidentally I'm beginning to notice that your method even if it worked would not be as lazy as you claim. Contrast: if( !istrue() ) return False; return True; versus istrue() or return( False ); return True; Net savings: 1 character. Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php