Re: [PHP] Adding new encodings to mbstring?
Haluk AKIN wrote: Hi all, Is it possible to add new character encodings to mbstring? http://us.php.net/mbstring If it is possible, then is there a procedure where I can submit new feature requests? Or is it possible for me to add the new character encodings myself? You can certainly add them yourself - which ones are you mising? /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Inspiration for a Tombstone.
Dotan Cohen wrote: As far as the programming practice that Colin was advocating, it is not a bad habit. And as far as the computer is concerned, the efficiency is a wash since the number of internal steps probably doesn't change much. However, it doesn't always work. (I know - no one claimed it did.) ?php if ($challenge_password_hash = $stored_password_hash) { echo 'Welcome to the club!'; } else { echo 'Stay out! This club is for members only!'; } ? Andrew In these instances you could rely on != behaviour instead of == behaviour, like this: ?php if ($challenge_password_hash != $stored_password_hash) { echo 'Stay out! This club is for members only!'; } else { echo 'Welcome to the club!'; } ? or, better yet: ?php if ($challenge_password_hash != $stored_password_hash) { echo 'Stay out! This club is for members only!'; exit; } echo 'Welcome to the club!'; // Lots of code here that just saved itself another indent in my IDE ? Indeed. The technique obviously only works for constants, and it wont help with variable - variable comparisons (unless you do something really stupid like put the first expression in quotes!). Using != when possible is a good idea but I guess you have to draw the line as to moving your preferred flow of logic around to fit in with a technique for reducing the possibility of logical errors. Even your example above hints at another political minefield - Early Return or Multiple Return Points (s/Return/Exit/ in this case) Let's not even go there!!! Col -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Early return (was: Inspiration for a Tombstone.)
2008/6/29 Colin Guthrie [EMAIL PROTECTED]: In these instances you could rely on != behaviour instead of == behaviour, like this: ?php if ($challenge_password_hash != $stored_password_hash) { echo 'Stay out! This club is for members only!'; } else { echo 'Welcome to the club!'; } ? or, better yet: ?php if ($challenge_password_hash != $stored_password_hash) { echo 'Stay out! This club is for members only!'; exit; } echo 'Welcome to the club!'; // Lots of code here that just saved itself another indent in my IDE ? Indeed. The technique obviously only works for constants, and it wont help with variable - variable comparisons (unless you do something really stupid like put the first expression in quotes!). Using != when possible is a good idea but I guess you have to draw the line as to moving your preferred flow of logic around to fit in with a technique for reducing the possibility of logical errors. Even your example above hints at another political minefield - Early Return or Multiple Return Points (s/Return/Exit/ in this case) Let's not even go there!!! Why not? I do this often, but I am not a professional programmer. I find this to be very useful. Dotan Cohen http://what-is-what.com http://gibberish.co.il א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing?
Re: [PHP] Early return (was: Inspiration for a Tombstone.)
At 3:30 PM +0300 6/29/08, Dotan Cohen wrote: 2008/6/29 Colin Guthrie [EMAIL PROTECTED]: Even your example above hints at another political minefield - Early Return or Multiple Return Points (s/Return/Exit/ in this case) Let's not even go there!!! Why not? I do this often, but I am not a professional programmer. I find this to be very useful. Dotan Cohen Start a new thread. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Early return (was: Inspiration for a Tombstone.)
2008/6/29 Colin Guthrie [EMAIL PROTECTED]: In these instances you could rely on != behaviour instead of == behaviour, like this: ?php if ($challenge_password_hash != $stored_password_hash) { echo 'Stay out! This club is for members only!'; } else { echo 'Welcome to the club!'; } ? or, better yet: ?php if ($challenge_password_hash != $stored_password_hash) { echo 'Stay out! This club is for members only!'; exit; } echo 'Welcome to the club!'; // Lots of code here that just saved itself another indent in my IDE ? Indeed. The technique obviously only works for constants, and it wont help with variable - variable comparisons (unless you do something really stupid like put the first expression in quotes!). Using != when possible is a good idea but I guess you have to draw the line as to moving your preferred flow of logic around to fit in with a technique for reducing the possibility of logical errors. Even your example above hints at another political minefield - Early Return or Multiple Return Points (s/Return/Exit/ in this case) Let's not even go there!!! Why not? I do this often, but I am not a professional programmer. I find this to be very useful. Dotan Cohen http://what-is-what.com http://gibberish.co.il א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing?
Re: [PHP] Early return (was: Inspiration for a Tombstone.)
2008/6/29 tedd [EMAIL PROTECTED]: Start a new thread. Done, sorry for the highjack. Dotan Cohen http://what-is-what.com http://gibberish.co.il א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing?
[PHP] Re: Early return (was: Inspiration for a Tombstone.)
Dotan Cohen wrote: Even your example above hints at another political minefield - Early Return or Multiple Return Points (s/Return/Exit/ in this case) Let's not even go there!!! Why not? I do this often, but I am not a professional programmer. I find this to be very useful. I think this was discussed on this list a while back... or perhaps it was just in an article I read... /me googles I think it stemmed from this article: http://www.theregister.co.uk/2007/12/04/multiple_exit_wounds/ See the comments to see how different folks agree/disagree. Personally I do use early return, and use it whenever possible. I find that deep nesting is actually harder to read and in many cases do stuff like: function foo($bar) { if ($bar) return true; return false; } Rather than: function foo($bar) { if ($bar) $rv = true; else $rv = false; return $rv; } If I did need to use a variable for a more complex function I almost always do: function foo($bar) { $rv = false; if ($bar) $rv = true; return $rv; } e.g I *always* define the variable at the scope in which I use it. Call me old fashioned but if I generally feel that in the example before last, $rv should not be defined outside of the if/else statement as it was not declared... I know PHP is very loose here, but from a C++ perspective: void foo(int bar) { if (bar) { int rv; rv = 1; } else { int rv; rv = 0; } return rv; } This clearly bombs. So you generally do: void foo(int bar) { int rv; if (bar) rv = 1; else rv = 0; return rv; } But then you could also do: void foo(int bar) { int rv = 0; if (bar) rv = 1; return rv; } And so this is how I generally structure my code in PHP too call me paranoid/stuck in my ways if you like :) I appreciate I've steered this away from early return :) Col -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Early return (was: Inspiration for a Tombstone.)
Dotan Cohen wrote: Why not? I do this often, but I am not a professional programmer. I find this to be very useful. Found another opinion/article about this. I remember reading this one a while back: http://whatimean.wordpress.com/2007/02/08/multiple-return-points-are-bad/ Like I said before, I don't personally subscribe to this point of view, but it makes for interesting reading :D Col -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Early return (was: Inspiration for a Tombstone.)
2008/6/29 Colin Guthrie [EMAIL PROTECTED]: Dotan Cohen wrote: Why not? I do this often, but I am not a professional programmer. I find this to be very useful. Found another opinion/article about this. I remember reading this one a while back: http://whatimean.wordpress.com/2007/02/08/multiple-return-points-are-bad/ Like I said before, I don't personally subscribe to this point of view, but it makes for interesting reading :D Thanks. He makes a good point. For my own one-man-show homepage, my multile-exit strategy is fine. But I do see the value in regard to code debugging and following the code flow. Dotan Cohen http://what-is-what.com http://gibberish.co.il א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing?
Re: [PHP] Re: Early return (was: Inspiration for a Tombstone.)
On Sun, 2008-06-29 at 17:47 +0300, Dotan Cohen wrote: 2008/6/29 Colin Guthrie [EMAIL PROTECTED]: Dotan Cohen wrote: Why not? I do this often, but I am not a professional programmer. I find this to be very useful. Found another opinion/article about this. I remember reading this one a while back: http://whatimean.wordpress.com/2007/02/08/multiple-return-points-are-bad/ Like I said before, I don't personally subscribe to this point of view, but it makes for interesting reading :D Thanks. He makes a good point. For my own one-man-show homepage, my multile-exit strategy is fine. But I do see the value in regard to code debugging and following the code flow. I'm a big fan of multiple early returns whenever possible, but once the code becomes more complex holding back until the end if possible. I find multiple early returns are very easy to read and then the purpose of the code doesn't get lost within the convolution of the logic. Similarly, I use the exact same approach with a loop from which I want to break/continue. I find it much clearer to see at the very beginning of a function or loop block exactly what easily fails to meet the criteria and is discarded early. Additionally, this makes the code more linear in that far fewer nestings are required. From that I'd argue that the more linear the code is, the more readable and understandable it is. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Early return (was: Inspiration for a Tombstone.)
At 3:25 PM +0100 6/29/08, Colin Guthrie wrote: Dotan Cohen wrote: Why not? I do this often, but I am not a professional programmer. I find this to be very useful. Found another opinion/article about this. I remember reading this one a while back: http://whatimean.wordpress.com/2007/02/08/multiple-return-points-are-bad/ Like I said before, I don't personally subscribe to this point of view, but it makes for interesting reading :D Whenever possible, I try to keep to a single return in my functions. For me it usually makes my life easier. However, there are times that if one insists on keeping to a single return doctrine, then the code can become very difficult to read because of additional code to maintain the requirement. I found an excellent example of this in DOM Scripting (page 99) by Keith where he takes a sea of curly braces and reduces them down a few false returns that appear immediately at the beginning of the function. So, in this case I clearly support multiple returns provided that they appear in a logical and obvious location (i.e., in the front of the function). Having multiple returns spread throughout a function is not conducive to providing the reader with easy comprehension as to what the function is doing (i.e., readability) -- which is the main reason for all of this concern anyway. When you can easily understand what your function is doing by inspection, then you are doing something right. Cheers, tedd PS: Nice try on the starting another thread. :-) -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Early return (was: Inspiration for a Tombstone.)
There is a point between Multiple early return vs. One last return, which is Efficiency. Imagine you have a code which makes lots of things. What is better in time? If you have early returns, your script will only do the operations it has to, nothing more than it has to do. If you have your data, but still keep calculating some other operations you don't need for this data (but maybe for another), and then you return, you are losing precious time of execution. And making things such as the showed above (for example): void foo(int bar) { int rv; if (bar) rv = 1; else rv = 0; return rv; } is not that good. Nor even the solution: function foo($bar) { if ($bar) return true; return false; } Think, that if you have something like $bar (a boolean variable), and if it is true, you return true, it is best to do this, is better, faster, and if the expression is simple is legible. function foo($bar) { return $bar } Notice that if $bar is true, foo will return true. If $bar is false, foo will return False. And what if I want to return false if $bar is true and viceversa? Simple as this: function foo($bar) { return !$bar; } Notice the ! symbol. Of course, it also is valid for expressions. What if have a function which returns true if I have a number even and the another is uneven? Should look like this function foo($even_number,$uneven_number) { return even($even_number) uneven($uneven_number); } And it works and it's simple. Supposing even( ) and uneven( ) functions return a boolean value y the variable passed is even and uneven. Cheers On Sun, Jun 29, 2008 at 17:35, tedd [EMAIL PROTECTED] wrote: At 3:25 PM +0100 6/29/08, Colin Guthrie wrote: Dotan Cohen wrote: Why not? I do this often, but I am not a professional programmer. I find this to be very useful. Found another opinion/article about this. I remember reading this one a while back: http://whatimean.wordpress.com/2007/02/08/multiple-return-points-are-bad/ Like I said before, I don't personally subscribe to this point of view, but it makes for interesting reading :D Whenever possible, I try to keep to a single return in my functions. For me it usually makes my life easier. However, there are times that if one insists on keeping to a single return doctrine, then the code can become very difficult to read because of additional code to maintain the requirement. I found an excellent example of this in DOM Scripting (page 99) by Keith where he takes a sea of curly braces and reduces them down a few false returns that appear immediately at the beginning of the function. So, in this case I clearly support multiple returns provided that they appear in a logical and obvious location (i.e., in the front of the function). Having multiple returns spread throughout a function is not conducive to providing the reader with easy comprehension as to what the function is doing (i.e., readability) -- which is the main reason for all of this concern anyway. When you can easily understand what your function is doing by inspection, then you are doing something right. Cheers, tedd PS: Nice try on the starting another thread. :-) -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Early return (was: Inspiration for a Tombstone.)
i am a big fan of multiple return. it save a lot of my time and it makes my code a lot more simple and readable. On 6/29/08, Roberto Costumero Moreno [EMAIL PROTECTED] wrote: There is a point between Multiple early return vs. One last return, which is Efficiency. Imagine you have a code which makes lots of things. What is better in time? If you have early returns, your script will only do the operations it has to, nothing more than it has to do. If you have your data, but still keep calculating some other operations you don't need for this data (but maybe for another), and then you return, you are losing precious time of execution. And making things such as the showed above (for example): void foo(int bar) { int rv; if (bar) rv = 1; else rv = 0; return rv; } is not that good. Nor even the solution: function foo($bar) { if ($bar) return true; return false; } Think, that if you have something like $bar (a boolean variable), and if it is true, you return true, it is best to do this, is better, faster, and if the expression is simple is legible. function foo($bar) { return $bar } Notice that if $bar is true, foo will return true. If $bar is false, foo will return False. And what if I want to return false if $bar is true and viceversa? Simple as this: function foo($bar) { return !$bar; } Notice the ! symbol. Of course, it also is valid for expressions. What if have a function which returns true if I have a number even and the another is uneven? Should look like this function foo($even_number,$uneven_number) { return even($even_number) uneven($uneven_number); } And it works and it's simple. Supposing even( ) and uneven( ) functions return a boolean value y the variable passed is even and uneven. Cheers On Sun, Jun 29, 2008 at 17:35, tedd [EMAIL PROTECTED] wrote: At 3:25 PM +0100 6/29/08, Colin Guthrie wrote: Dotan Cohen wrote: Why not? I do this often, but I am not a professional programmer. I find this to be very useful. Found another opinion/article about this. I remember reading this one a while back: http://whatimean.wordpress.com/2007/02/08/multiple-return-points-are-bad/ Like I said before, I don't personally subscribe to this point of view, but it makes for interesting reading :D Whenever possible, I try to keep to a single return in my functions. For me it usually makes my life easier. However, there are times that if one insists on keeping to a single return doctrine, then the code can become very difficult to read because of additional code to maintain the requirement. I found an excellent example of this in DOM Scripting (page 99) by Keith where he takes a sea of curly braces and reduces them down a few false returns that appear immediately at the beginning of the function. So, in this case I clearly support multiple returns provided that they appear in a logical and obvious location (i.e., in the front of the function). Having multiple returns spread throughout a function is not conducive to providing the reader with easy comprehension as to what the function is doing (i.e., readability) -- which is the main reason for all of this concern anyway. When you can easily understand what your function is doing by inspection, then you are doing something right. Cheers, tedd PS: Nice try on the starting another thread. :-) -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- 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] Re: Early return (was: Inspiration for a Tombstone.)
Robert Cummings wrote: I'm a big fan of multiple early returns whenever possible, but once the code becomes more complex holding back until the end if possible. I find multiple early returns are very easy to read and then the purpose of the code doesn't get lost within the convolution of the logic. Similarly, I use the exact same approach with a loop from which I want to break/continue. I find it much clearer to see at the very beginning of a function or loop block exactly what easily fails to meet the criteria and is discarded early. Additionally, this makes the code more linear in that far fewer nestings are required. From that I'd argue that the more linear the code is, the more readable and understandable it is. I think you've captured very eloquently exactly how I feel about this! I've often thought that the if you disagree about early return then you automatically have to hate the whole continue/break thing too when used in loops - basically language *features*. I do concede (as you do) that there are times when the code benefits from nesting rather than early return/break/continue/exit. Col -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] CURL de-bugging: So why am I not getting the results page on the target site?
For those that like CURL and calendars. Using CURL, I am accessing a form on a 'target' third party site (it is built around JavaScript DHTML DatePicker) and trying to POST various date and other inputs from its form and return the results page to my site for further processing with php. However, I can only get the inputs page returned. The third party site works fine when submitted from a browser. I have tried testing various ways. I put the source code of the target inputs page on my site. I then changed the form to method=get and checked that my CURL expressions curl_setopt($curl_session, CURLOPT_POSTFIELDS,variable_name) were all in the right order and had the correct HTML substitutions for colons and spaces etc. Testing whether eg the submit variable has been posted, I get a good result. Here is the bit of testing code on the test page: if(ISSET($_POST[SubmitButton])$_POST{SubmitButton}==SubmitButton Value) { print(brsubmitted - test.php page line 32); // I can get this } else { print(brnot submitted - test.php page line 35 ); } I have 17 variables being submitted. I do notice that I only get the above result if the curl_setopt($curl_session, CURLOPT_POSTFIELDS,submit_variable_name) is written in the calling page as the last in these expressions, whereas in the list of GET variables it comes 14th. This worries me, it does not seem to be a problem with other variables, perhaps because the submit variable has a value with a space in it (becomes +). curl_setopt($curl_sess, CURLOPT_POSTFIELDS,Control%3ACheck_0%3AButton=Submit+This); Thank you for staying with me so far. I read that variables need to be in the right order for some reason. I suspected that the page was trying to avoid spoofing by using sessions, but when I deleted all cookies on my computer and submit from the input page using a browser, I still got back a results page but not from the script. So lack of sessions data was not what stops the page responding. The input form page actually is coded as an aspx page. It uses various javascripts and hidden fields like _EVENTTARGET, __EVENTARGUMENT, __LASTFOCUS, __VIEWSTATE (below). The last is an encrypted version of the page to enable the Back button to work. I suppose this could include something like a timestamp that stops CURL requests. If interested, I can send you the actual URLs. Any ideas on how to grab this result page? John PS VIEWSTATE curl_setopt($ch,
[PHP] unset in foreach breaks recrusion
Hello everyone! A couple of days ago I submitted a bug to PHP http://bugs.php.net/bug.php?id=45385 But I was mistaken, apparently it's not a bug. And I was sent here to get help. Although I did tried what was suggested in the response, Actually I tried it before I wrote about the bug, as I found few _similar_ bugs to the one I submitted, but it does not help. The things is if you run the recursion (take the script from the link above) it will break at the deepest child, it can be the second cycle or the nth. So before I write a reply to the bug i submitted, I wanted to know if there's something I'm missing with this? Thanks! David. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php