[PHP] RE: Multiple return statements in a function.
Well, the latter method is generally easier to understand later. Most programming style books preach this method, and it's the one that most of my previous employers use. Cheers... -Original Message- From: Peter van der Does [mailto:pvanderd...@gmail.com] Sent: Thursday, April 23, 2009 8:13 AM To: php-general@lists.php.net Subject: Multiple return statements in a function. I tend to put my return value in a variable and at the end of the function I have 1 return statement. I have seen others doing returns in the middle of the function. Example how I do it: function check($a) { $return=''; if ( is_array( $a ) ) { $return='Array'; } else { $return='Not Array'; } return $return; } Example of the other method: function check($a) { if ( is_array( $a ) ) { return ('Array'); } else { return ('Not Array'); } } What is your take? And is there any benefit to either method? -- Peter van der Does GPG key: E77E8E98 Blog: http://blog.avirtualhome.com Forums: http://forums.avirtualhome.com Jabber ID: pvanderd...@gmail.com GetDeb Package Builder http://www.getdeb.net - Software you want for Ubuntu -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Encrypting email
On Tue, 21 Apr 2009 08:39:25 -0400, Bob McConnell wrote: >I have been asked by a product manager what our options are for >encrypting email messages with sensitive information. We are currently >using PHPMailer to send email. What can be done to encrypt those >messages? Can it be done without OOP? > >Server configuration: > RHEL 5 > Apache 2.0 > PHP 5.2.3 > PHPMailer 1.73 Use S/MIME, and nearly all of your clients will be able to decrypt your emails. There are a few exceptions: Forté Agent still doesn't handle S/MIME, and Eudora needs a plug-in to handle it. However, all mainstream email programs support it directly, without need to install new software. You need to generate (or purchase - I prefer generate for free in OpenSSL) email certificates for encrypting emails, then distribute the certificates to allow people to decrypt them. Once they have the key, the emails generally just automatically decrypt when you view them (depending on the email program). NB: give your clients individual certificates, and keep the public keys to encrypt the emails to them. PHP has support for this, and it's easy to use: http://au2.php.net/manual/en/function.openssl-pkcs7-encrypt.php Apparently, PHPMailer supports it too so check that out. -- Ross McKay, Toronto, NSW Australia "Let the laddie play wi the knife - he'll learn" - The Wee Book of Calvin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] MySQL -- finding whether there's a transaction started
Bogdan Stancescu wrote: Hello list, I'm developing a library and would need to know if the code calling my library has already started a MySQL transaction or not. I want to know whether I should start one or use savepoints instead -- starting a transaction if one is already in progress commits the existing transaction, and setting a savepoint silently fails outside transactions. And I was unable to find any non-destructive way of retrieving that information -- is there any? I don't think mysql has any way of finding that out. If you're using an abstraction layer, it's easy enough in code - though rollback's are a little harder - should they do a complete rollback or just to a savepoint? class db { private $transaction_count = 0; public function startTransaction() { if ($this->transaction_count == 0) { mysql_query("BEGIN"); } else { mysql_query("SAVEPOINT"); } $this->transaction_count++; } public function commitTransaction() { // you can't commit a transaction if there's more than one "open" // so just decrement the counter if ($this->transaction_count > 1) { $this->transaction_count--; return; } $this->transaction_count = 0; mysql_query("COMMIT"); } } Now you can just call $db->startTransaction(); and $db->commitTransaction(); and it'll handle the stuff for you. -- Postgresql & php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Unable to send mail from PHP to AT&T e-mail address
the ini_set (or you can set the 5th param to the mail() function) is a return-path. If the message bounces (recipient's mailbox full, server down, whatever the reason) it gets delivered to that address. They serve different purposes. The dirty little secret that nobody seems to know is that the RFCs reserve Return-path for use by the MTA servers. It can be replaced by any of them in the routing chain and is used when mail crosses into or out of SMTP networks. If you want a return address other than From to stick all the way through, you have to use the Reply-to and/or Sender headers. Emails don't bounce to those addresses though do they? I've always thought the return-path is where an email is bounced to and reply-to etc are used by mail clients, not the mta's. -- Postgresql & php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkboxes
tedd wrote: At 4:58 PM -0400 4/23/09, PJ wrote: >>> tedd wrote: >>> > http://php1.net/a/edit-db-demo/ >>> >H I've looked at your demo and, frankly, don't see it working. When I enter names and click on one of the search buttons, I don't get sane results. For instance, entering Johnson in last name and John in first name, I click on search first name and I get an entry from page R for first name John and Last name Raab. Doesn't make sense. PJ: Okay, if you enter "Johnson" in the last name text box and click the "Search Last Name" button, the demo will provide you with a record that has "Johnson" as the last name. Likewise, if you enter "John" in the first name text-box and click the "Search First Name" button, the demo will provide you with a record that has "John" as the first name. Both of those work -- so, where's the confusion? Apparently you want to enter "Johnson" in the last name text box and "John" in the first name text box and then click something to find that specific name right? Well, the demo is not set-up that way -- there is no "Click here and I'll find the specific person who has this first and last name". The demo is set up to search for first OR last name OR email address. It also provides a way to sort the records such that one can sequentially step any sort made on first-name/last-name; or last-name/first-name; or email address. It only does what it says it does. Did you review the instructions at the bottom? Cheers, tedd Tedd, nice looking contact demo thingy.. but PJ has a point. ;-) It would make the app perhaps more intuitive if one could just type text in any of the 3 fields and then spit out results that match all of the comparisons that are not blank by clicking one button. .. not to take away from what you have done, but perhaps a future evolution of the demo. Donovan -- =o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o D. BROOKE EUCA Design Center WebDNA Software Corp. WEB:> http://www.euca.us | http://www.webdna.us =o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o WebDNA: [** Square Bracket Utopia **] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkboxes
At 4:58 PM -0400 4/23/09, PJ wrote: >>> tedd wrote: >>> > http://php1.net/a/edit-db-demo/ >>> >H I've looked at your demo and, frankly, don't see it working. When I enter names and click on one of the search buttons, I don't get sane results. For instance, entering Johnson in last name and John in first name, I click on search first name and I get an entry from page R for first name John and Last name Raab. Doesn't make sense. PJ: Okay, if you enter "Johnson" in the last name text box and click the "Search Last Name" button, the demo will provide you with a record that has "Johnson" as the last name. Likewise, if you enter "John" in the first name text-box and click the "Search First Name" button, the demo will provide you with a record that has "John" as the first name. Both of those work -- so, where's the confusion? Apparently you want to enter "Johnson" in the last name text box and "John" in the first name text box and then click something to find that specific name right? Well, the demo is not set-up that way -- there is no "Click here and I'll find the specific person who has this first and last name". The demo is set up to search for first OR last name OR email address. It also provides a way to sort the records such that one can sequentially step any sort made on first-name/last-name; or last-name/first-name; or email address. It only does what it says it does. Did you review the instructions at the bottom? 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
Re: [PHP] checkboxes
PJ wrote: > tedd wrote: > >> At 10:11 AM -0400 4/23/09, PJ wrote: >> >>> tedd wrote: >>> > http://php1.net/a/edit-db-demo/ >>> Here a user can search for a Last name, first name, or email. Note, there's no checkboxes because the user indicates what they are searching for by where they place their search criteria. HTH's tedd >>> Thanks Tedd, >>> Your demod uses javascript and I don't really want to use javascript. >>> Apparently it is more open to hacking than just plain PHP/MySQL. ?? >>> Also, I seem to have things going fairly well - it's a neat way to learn >>> coding, especially when adjusting for things you hadn't planned in >>> advance, like if the user forgets to enter data or doesn't click on the >>> radio button. And then implementing the warnings and reloading (or not >>> reloading the page) to keep the data entered upon omission or >>> unacceptable entries. Get's hairy sometimes, but it's quite >>> enlightening. ;-) >>> >> Come-on, my demo uses a single javascript routine to ask the user IF >> they want to delete something. If javascript is turned off, my demo >> still works. This is just an example of enhancement with graceful >> degradation. It has nothing to do with the demo other than that. >> >> The point of my showing you the demo was to simply suggest that you >> forgo the checkboxes and go straight to the "Search" entry. After all, >> that tells you everything you want to know about what the user wants >> to do, right? >> >> Why have the user click a checkbox showing that they want to search >> for a book title and then also have then enter in the book title? Why >> not just have them enter the book title and be done with it? >> >> It might serve you well to rethink what you are wanting to do. >> >> Cheers, >> >> tedd >> >> >> > Oh, Ok. Will check it out then. :-) At worst, I'll set it up and see > how it plays ooh, well... another lesson to learn... ;-) > > H I've looked at your demo and, frankly, don't see it working. When I enter names and click on one of the search buttons, I don't get sane results. For instance, entering Johnson in last name and John in first name, I click on search first name and I get an entry from page R for first name John and Last name Raab. Doesn't make sense. Anyway, I have my setup working using $_POST which gives me an array of the inputs plus the submit string all in a one-dimensional array. Great. Now I'm playing with how to set things up to eliminate extraneous inputs which will be made, will, will not. So, filtering becomes rather important and complicated. I thought switch would work, but it doesn't look promising. I can clear the 'submit' string by declaring $_POST['submit'] = ""; at top of page; which seems strange?? But I can't figure out how to eliminate or avoid extraneous inputs. In other words, If I have input in the Search Title field and input in any one or all of the other search options, clicking on Search Title the returned array includes all options I'm not sure how to filter that. :-\ Is there some way to set the other inputs to null when choosing the search? Without js? -- unheralded genius: "A clean desk is the sign of a dull mind. " - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkboxes
PJ wrote: > tedd wrote: > >> At 10:11 AM -0400 4/23/09, PJ wrote: >> >>> tedd wrote: >>> > http://php1.net/a/edit-db-demo/ >>> Here a user can search for a Last name, first name, or email. Note, there's no checkboxes because the user indicates what they are searching for by where they place their search criteria. HTH's tedd >>> Thanks Tedd, >>> Your demod uses javascript and I don't really want to use javascript. >>> Apparently it is more open to hacking than just plain PHP/MySQL. ?? >>> Also, I seem to have things going fairly well - it's a neat way to learn >>> coding, especially when adjusting for things you hadn't planned in >>> advance, like if the user forgets to enter data or doesn't click on the >>> radio button. And then implementing the warnings and reloading (or not >>> reloading the page) to keep the data entered upon omission or >>> unacceptable entries. Get's hairy sometimes, but it's quite >>> enlightening. ;-) >>> >> Come-on, my demo uses a single javascript routine to ask the user IF >> they want to delete something. If javascript is turned off, my demo >> still works. This is just an example of enhancement with graceful >> degradation. It has nothing to do with the demo other than that. >> >> The point of my showing you the demo was to simply suggest that you >> forgo the checkboxes and go straight to the "Search" entry. After all, >> that tells you everything you want to know about what the user wants >> to do, right? >> >> Why have the user click a checkbox showing that they want to search >> for a book title and then also have then enter in the book title? Why >> not just have them enter the book title and be done with it? >> >> It might serve you well to rethink what you are wanting to do. >> >> Cheers, >> >> tedd >> >> >> > Oh, Ok. Will check it out then. :-) At worst, I'll set it up and see > how it plays ooh, well... another lesson to learn... ;-) > Gee, Tedd, That was fun. You were right. It's a hell-of-a-lot simpler. I did get the complicated way to work as well... :-D but your suggestion is much simpler. The KISS principle always wins out! Thanks again. Phil -- unheralded genius: "A clean desk is the sign of a dull mind. " - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] bug or expected, mbstring.func_overload not changeable by .htaccess 5.2.8/5.2.9
Hello, Sorry for the late reply. no problem. The ini_set is meant to be used inside a php script not in an .htaccess file. So perhaps you could test this in a script specific manner. i know;) i do php/apache for some years... i found out the problem in meanwhile. http://bugs.php.net/bug.php?id=47187&edit=1 Its not allowed anymore, just not documented. formerly bug was fixed by deactivating ;) thats a pitty cause the patch for 3rd party patch for ~5.2.6 for mentioned bug worked really good. :( Thanks, Andre -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how to determine if a mysql query returns an empty set?
Andrew Ballard wrote: It won't be any of those because the query is successful even if it returns no records. You could use http://us2.php.net/manual/en/mysqli-stmt.num-rows.php to determine how many rows were returned. Andrew Oh ok, thanks that makes sense. Thanks for the link also -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how to determine if a mysql query returns an empty set?
Nitsan Bin-Nun wrote: mysql_num_rows() maybe? if not I probably haven't understood your question. Thanks, I never thought of trying that. This code works! $mysqli_get_requests = mysqli_query($mysqli,$get_requests); if (!mysqli_num_rows($mysqli_get_requests)) { echo "You have reached the end of the results. Please press the back button. "; exit; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how to determine if a mysql query returns an empty set?
On Thu, Apr 23, 2009 at 2:12 PM, Adam Williams wrote: > Is there a way to determine if a mysql query returns an empty set? I am > selecting 10 results at a time with a limit statement and need to know when > i've ran out of rows. I've only got 2 rows in the database, so when I start > with row 10, it returns an empty set. I have the following code: > > //running this query gives "Empty set (0.00 sec)" in mysql console. > > $get_requests = "select form_id, full_name, email, phone, division, > location, date_format(time_of_request, '%m-%d-%Y %r') as time_of_request, > contact_time, problem, accepted_by, date_format(accepted_time, '%m-%d-%Y > %r') as accepted_time, resolution, date_format(resolution_time, '%m-%d-%Y > %r') as resolution_time from form where ((stage = 'Closed') && (email = > 'awilliam' )) order by resolution_time limit 10 , 10" > > //checks to see if it returns nothing, then print that you are at the end of > the results > > if (!$mysqli_get_requests = > mysqli_query($mysqli,$get_requests)) > { > echo "You have reached the end of the results. > Please press the back button. > type=submit value=Back > name=submit>"; > exit; > } > > but that doesn't work, because I guess an empty set is not false, 0, or > NULL? > > > It won't be any of those because the query is successful even if it returns no records. You could use http://us2.php.net/manual/en/mysqli-stmt.num-rows.php to determine how many rows were returned. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how to determine if a mysql query returns an empty set?
mysql_num_rows() maybe? if not I probably haven't understood your question. On Thu, Apr 23, 2009 at 8:12 PM, Adam Williams wrote: > Is there a way to determine if a mysql query returns an empty set? I am > selecting 10 results at a time with a limit statement and need to know when > i've ran out of rows. I've only got 2 rows in the database, so when I start > with row 10, it returns an empty set. I have the following code: > > //running this query gives "Empty set (0.00 sec)" in mysql console. > > $get_requests = "select form_id, full_name, email, phone, division, > location, date_format(time_of_request, '%m-%d-%Y %r') as time_of_request, > contact_time, problem, accepted_by, date_format(accepted_time, '%m-%d-%Y > %r') as accepted_time, resolution, date_format(resolution_time, '%m-%d-%Y > %r') as resolution_time from form where ((stage = 'Closed') && (email = > 'awilliam' )) order by resolution_time limit 10 , 10" > > //checks to see if it returns nothing, then print that you are at the end > of the results > > if (!$mysqli_get_requests = > mysqli_query($mysqli,$get_requests)) > { > echo "You have reached the end of the results. > Please press the back button. > type=submit value=Back > name=submit>"; > exit; > } > > but that doesn't work, because I guess an empty set is not false, 0, or > NULL? > > >
Re: RES: [PHP] Extract variable out of a Class -> Function
Yes!!! It works!! Thats' exactly what I was looking for ... getting the value of $justTT in $othervar. I'm new to classes ... thus the noobity! On Apr 23, 2009, at 2:04 PM, Jônatas Zechim wrote: Class Test { function showOutput { if ($this->url) { $this->justTT = substr($this->url,-10,7); } } } $myvar=new Test(); $myvar->showOutput(); $othervar=$myvar->justTT; echo $othervar; $otherClass=new anotherclass($othervar); Is that u want? Zechim SP/Brazil -Mensagem original- De: Rahul S. Johari [mailto:sleepwal...@rahulsjohari.com] Enviada em: quinta-feira, 23 de abril de 2009 14:56 Para: php-general@lists.php.net Assunto: [PHP] Extract variable out of a Class -> Function I have a function within a class. There is a variable inside that function which I need to access & use outside of the class/function. For example ... Class Test { function showOutput { if ($this->url) { $justTT = substr($this->url,-10,7); echo $justTT; } } } I need to use $justTT. How do I get the value of $justTT into a different variable outside of this class/function so I can use it in a different class? --- Rahul Sitaram Johari Founder, Internet Architects Group, Inc. [Email] sleepwal...@rahulsjohari.com [Web] http://www.rahulsjohari.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] how to determine if a mysql query returns an empty set?
Is there a way to determine if a mysql query returns an empty set? I am selecting 10 results at a time with a limit statement and need to know when i've ran out of rows. I've only got 2 rows in the database, so when I start with row 10, it returns an empty set. I have the following code: //running this query gives "Empty set (0.00 sec)" in mysql console. $get_requests = "select form_id, full_name, email, phone, division, location, date_format(time_of_request, '%m-%d-%Y %r') as time_of_request, contact_time, problem, accepted_by, date_format(accepted_time, '%m-%d-%Y %r') as accepted_time, resolution, date_format(resolution_time, '%m-%d-%Y %r') as resolution_time from form where ((stage = 'Closed') && (email = 'awilliam' )) order by resolution_time limit 10 , 10" //checks to see if it returns nothing, then print that you are at the end of the results if (!$mysqli_get_requests = mysqli_query($mysqli,$get_requests)) { echo "You have reached the end of the results. Please press the back button. "; exit; } but that doesn't work, because I guess an empty set is not false, 0, or NULL?
Re: [PHP] Extract variable out of a Class -> Function
I have a function within a class. There is a variable inside that function which I need to access & use outside of the class/function. For example ... Class Test { function showOutput { if ($this->url) { $justTT = substr($this->url,-10,7); echo $justTT; } } } I need to use $justTT. How do I get the value of $justTT into a different variable outside of this class/function so I can use it in a different class? Return it? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Extract variable out of a Class -> Function
I have a function within a class. There is a variable inside that function which I need to access & use outside of the class/function. For example ... Class Test { function showOutput { if ($this->url) { $justTT = substr($this->url,-10,7); echo $justTT; } } } I need to use $justTT. How do I get the value of $justTT into a different variable outside of this class/function so I can use it in a different class? --- Rahul S. Johari Supervisor, Internet & Administration Informed Sources, Inc. [Email] ra...@troyjobs.com [Web] https://www.informed-sources.com [Phone] 518-687-6700 Ext: 154 [Fax] 518-687-6799 --- Rahul Sitaram Johari Founder, Internet Architects Group, Inc. [Email] sleepwal...@rahulsjohari.com [Web] http://www.rahulsjohari.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Symlinks and ownership
On Thu, Apr 23, 2009 at 13:21, Christoph Boget wrote: > Is there a reason why you can't programatically set ownership of a > symbolic ink? The following code You can't do it from the command line either, Chris. This is because chown and chgrp automatically dereference symlinks, so it's actually changing ownership of the target. > yet when I go take a look at it in the directory, the group for the > link has not been changed to what I set it to. Is that not something > you can do for symbolic links programatically? To modify ownership of a symlink, you should instead use something in the exec() family (exec(), passthru(), system(), etc.) and run the command as if from the command line, with the option explicitly set *not* to dereference symbolic links (which is -h or --no-dereference): -- daniel.br...@parasane.net || danbr...@php.net http://www.parasane.net/ || http://www.pilotpig.net/ 50% Off All Shared Hosting Plans at PilotPig: Use Coupon DOW1 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: unzip a file - destination folder wrong
> >> >> $fp = fopen(dirname($filename) . '/' . zip_entry_name($zip_entry), "w"); >> >> > thank you this worked. How come the . '/' . zip_entry_name($zip_entry) is > needed? Looks like a double file name, but the result is ok. Could you > explain this line? read carefully, you'll understand too. :) its extracting the directory name with the dirname($filename) then concatenation with the name of zip file only :) regards Lenin www.twitter.com/nine_L
[PHP] Symlinks and ownership
Is there a reason why you can't programatically set ownership of a symbolic ink? The following code if( symlink( TARGET, LINK )) { echo 'Successfully created ' . LINK . "\n"; if( @chown( LINK, NEW_UID )) { echo 'Successfully changed ownership for ' . LINK . "\n"; if( @chgrp( LINK, NEW_UID )) { echo 'Successfully changed group for ' . LINK . "\n"; } } } echos out: Successfully created XXX Successfully changed ownership for XXX Successfully changed group for XXX yet when I go take a look at it in the directory, the group for the link has not been changed to what I set it to. Is that not something you can do for symbolic links programatically? thnx, Christoph -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: unzip a file - destination folder wrong
Merlin Morgenstern wrote: > > > Shawn McKenzie wrote: >> Merlin Morgenstern wrote: >>> Hi there, >>> >>> I am trying to unzip a zip file. Therefore I am using this function: >>> >>> # unzip a file >>> function extract_zipfile($filename){ >>> $zip = zip_open($filename); >>> if ($zip) { >>> while ($zip_entry = zip_read($zip)) { >>> $fp = fopen(zip_entry_name($zip_entry), "w"); >>> if (zip_entry_open($zip, $zip_entry, "r")) { >>> $buf = zip_entry_read($zip_entry, >>> zip_entry_filesize($zip_entry)); >>> fwrite($fp,"$buf"); >>> zip_entry_close($zip_entry); >>> fclose($fp); >>> } >>> } >>> zip_close($zip); >>> } >>> } >>> >>> It works, but unfortunatelly the extracted files are all placed into the >>> directory where the php file is located. Not where the original zip file >>> was found. I tried to add the directory to fwrite, but without success. >>> >>> Does somebody know where to specify the target directory? >>> >>> Thank you for any help, >>> >>> Merlin >> >> Try this: >> >> $fp = fopen(dirname($filename) . '/' . zip_entry_name($zip_entry), "w"); >> > > thank you this worked. How come the . '/' . zip_entry_name($zip_entry) > is needed? Looks like a double file name, but the result is ok. Could > you explain this line? Thank you! > > Kind regards Well, I've never used the zip functions, but it appears taht $zip_entry is a resource for the entry in the zip file zip_entry_name($zip_entry) returns the path and name of the entry in the zip file. So you need to get the dir of the actual zip file and then append the name of the file in the zip. -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] ReflectionMethod::invokeArgs
Hi! Please, tell me what's ReflectionMethod::invokeArgs first param for? Since method always know it's class and it can only be invoked on it's own class. Regards, K.L. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] bug or expected, mbstring.func_overload not changeable by .htaccess 5.2.8/5.2.9
Hello, Besides the .htaccess which might be an apache configuration problem if you use ini_set("mbstring.func_overload",2) in a script of this directory does it work? no, also the ini_set does not work for this Directive. Sorry for the late reply. The ini_set is meant to be used inside a php script not in an .htaccess file. So perhaps you could test this in a script specific manner. In addition to this heck your apache configuration to see if you allow .htaccess to be parsed. apache and .htaccess are ok i added a scond line which changes mbstring.encoding_translation from off to on without problems: Directive Local Value Master Value mbstring.encoding_translation On Off mbstring.func_overload 0 0 .htaccess: php_value mbstring.func_overload 2 php_flag mbstring.encoding_translation On IMHO this is not a good practice using .htaccess to alter php's behavior. Perhaps you should consider ini_set after all. Can you confirm or rebut this behavior? Should we go to internals list? Thanks, Andre Unfortunately I can confirm that. This is a list with all the initial values you are allowed to change: http://www.php.net/manual/en/ini.list.php This is a script that shows all the mbstring extension values in an array: "; print_r(ini_get_all('mbstring')); ?> This array contains the default,local values and access level for each one. Note that according to the manual: http://www.php.net/ini_get_all The access levels for every value are:| Constant Value Meaning PHP_INI_USER 1 Entry can be set in user scripts PHP_INI_PERDIR2 Entry can be set in php.ini, .htaccess or httpd.conf PHP_INI_SYSTEM4 Entry can be set in php.ini or httpd.conf PHP_INI_ALL 7 Entry can be set anywhere |Although in the ini list the mbstring is supposed to have access level 2 I've noticed that I have access level 4 for mbstring.func_overload. Perhaps *this is the problem*. You have access level 4 so that is why you can't change the value using .htaccess. I don't know if this is an expected behavior though. Can anyone else confirm this?? -- Thodoris
Re: [PHP] @$_POST[...]
Chris wrote: > Luke wrote: >> 2009/4/22 PJ >> >>> Could somebody explain to me the meaning of @ in $var = >>> @$_POST['title'] ; >>> where could I find a cheat sheet for those kinds of symbols or what are >>> they called? >>> Sorry for my ignorance, but maybe this will take the fog filter our of >>> my neurons. :-\ >> I believe placing an @ in front of a statement suppresses any error >> messages >> it generates. >> > > It does - in this case if 'title' is not posted as part of the form, > it would have generated a warning or notice (can't remember which). > > A longer path is: > > $var = ''; > if (isset($_POST['title'])) { > $var = $_POST['title']; > } > > The shortcut works but it makes it extremely difficult to find > problems with your scripts (think of 50 @'s being used in one script.. > eek). > Thanks for refreshing my memory... I had run across this but forgot as I usually do not use it. I turn on all error checking and stumble through prin_r() and var_dump() ... whatever. :-D -- unheralded genius: "A clean desk is the sign of a dull mind. " - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkboxes
tedd wrote: > At 10:11 AM -0400 4/23/09, PJ wrote: >> tedd wrote: >> > http://php1.net/a/edit-db-demo/ >>> >>> Here a user can search for a Last name, first name, or email. Note, >>> there's no checkboxes because the user indicates what they are >>> searching for by where they place their search criteria. >>> >>> HTH's >>> >>> tedd >> Thanks Tedd, >> Your demod uses javascript and I don't really want to use javascript. >> Apparently it is more open to hacking than just plain PHP/MySQL. ?? >> Also, I seem to have things going fairly well - it's a neat way to learn >> coding, especially when adjusting for things you hadn't planned in >> advance, like if the user forgets to enter data or doesn't click on the >> radio button. And then implementing the warnings and reloading (or not >> reloading the page) to keep the data entered upon omission or >> unacceptable entries. Get's hairy sometimes, but it's quite >> enlightening. ;-) > > Come-on, my demo uses a single javascript routine to ask the user IF > they want to delete something. If javascript is turned off, my demo > still works. This is just an example of enhancement with graceful > degradation. It has nothing to do with the demo other than that. > > The point of my showing you the demo was to simply suggest that you > forgo the checkboxes and go straight to the "Search" entry. After all, > that tells you everything you want to know about what the user wants > to do, right? > > Why have the user click a checkbox showing that they want to search > for a book title and then also have then enter in the book title? Why > not just have them enter the book title and be done with it? > > It might serve you well to rethink what you are wanting to do. > > Cheers, > > tedd > > Oh, Ok. Will check it out then. :-) At worst, I'll set it up and see how it plays ooh, well... another lesson to learn... ;-) -- unheralded genius: "A clean desk is the sign of a dull mind. " - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] How can I detect an exception without using try/catch?
Specifically, the __destruct() method of certain objects will be called if an object goes out of scope due to an exception. Since the __destruct() method didn't call the code that caused the exception, it can't catch it. I need the __destruct() method to behave differently if it's called while an exception is in progress than if it's called simply because the object is unset. Searches of the docs has yet to turn up anything and Google isn't helping. Anyone have any pointers? -- Bill Moran http://www.potentialtech.com http://people.collaborativefusion.com/~wmoran/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multiple return statements in a function.
At 10:25 AM -0400 4/23/09, Robert Cummings wrote: On Thu, 2009-04-23 at 10:14 -0400, tedd wrote: > However, I am saying (after years of reading other people's code) it is generally much easier to read code that follows "Structured Programming" than it is to read code that doesn't. Actually I use an early return as much as possible also. If there are 5 conditions which disqualify the rest of the function from running then they'll all be listed one after the other at the top of the function. This way it's very easy to see exactly what doesn't qualify for evaluation. Additionally, it saves on the need for that many levels of indentation or making an overly complex conditional. I find it much more intuitive than mentally tracking several levels of indentation and scrolling to the bottom of the function. Cheers, Rob. Rob: Again, I'm not arguing the point -- we actually agree. I have functions where I do that as well. My only criteria is how easy my functions are to read and understand. If by placing function entry-criteria at the beginning of the function and then returning nulls (or whatever) makes it easier for someone to review your code and understand what it does, then by all means do it. But I am sure that both of you have reviewed functions that have multiple returns spread throughout where you thought "What the hell is this? Just what is this function returning?" That is what I am addressing. The OP asked which was the better practice and I replied that it is USUALLY good practice to have only one return and have it at the end of your function -- I stand by that. 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
Re: [PHP] Multiple return statements in a function.
On Thu, Apr 23, 2009 at 10:14:28AM -0400, tedd wrote: > At 2:19 PM +0100 4/23/09, Tony Marston wrote: >> There is no such "rule", it is a matter of personal preference. As a >> previous poster has already said, if you want to leave a function early >> and >> ignore all subsequent processing it is easier to understand if you return >> immediately rather than have a mechanism to jump over the remaining code >> to >> a single return point. In the good old days we used to use the GOTO in >> COBOL >> to jump to the exit point, but then people found a way to abuse GOTO in >> very >> imaginatve ways. >> >>> The "benefit" is easier to read code. >> >> I think that an immediate return is easier to read, but what do I know - >> I've only been programming for 30 years. >> >> -- >> Tony Marston > > Tony: > > Don't get your panties in a knot. :-) I think in Tony's case, it would "knickers in a twist". ;-} Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: unzip a file - destination folder wrong
Shawn McKenzie wrote: Merlin Morgenstern wrote: Hi there, I am trying to unzip a zip file. Therefore I am using this function: # unzip a file function extract_zipfile($filename){ $zip = zip_open($filename); if ($zip) { while ($zip_entry = zip_read($zip)) { $fp = fopen(zip_entry_name($zip_entry), "w"); if (zip_entry_open($zip, $zip_entry, "r")) { $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); fwrite($fp,"$buf"); zip_entry_close($zip_entry); fclose($fp); } } zip_close($zip); } } It works, but unfortunatelly the extracted files are all placed into the directory where the php file is located. Not where the original zip file was found. I tried to add the directory to fwrite, but without success. Does somebody know where to specify the target directory? Thank you for any help, Merlin Try this: $fp = fopen(dirname($filename) . '/' . zip_entry_name($zip_entry), "w"); thank you this worked. How come the . '/' . zip_entry_name($zip_entry) is needed? Looks like a double file name, but the result is ok. Could you explain this line? Thank you! Kind regards -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: unzip a file - destination folder wrong
Merlin Morgenstern wrote: > Hi there, > > I am trying to unzip a zip file. Therefore I am using this function: > > # unzip a file > function extract_zipfile($filename){ > $zip = zip_open($filename); > if ($zip) { > while ($zip_entry = zip_read($zip)) { > $fp = fopen(zip_entry_name($zip_entry), "w"); > if (zip_entry_open($zip, $zip_entry, "r")) { > $buf = zip_entry_read($zip_entry, > zip_entry_filesize($zip_entry)); > fwrite($fp,"$buf"); > zip_entry_close($zip_entry); > fclose($fp); > } > } > zip_close($zip); > } > } > > It works, but unfortunatelly the extracted files are all placed into the > directory where the php file is located. Not where the original zip file > was found. I tried to add the directory to fwrite, but without success. > > Does somebody know where to specify the target directory? > > Thank you for any help, > > Merlin Try this: $fp = fopen(dirname($filename) . '/' . zip_entry_name($zip_entry), "w"); -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] unzip a file - destination folder wrong
Hi there, I am trying to unzip a zip file. Therefore I am using this function: # unzip a file function extract_zipfile($filename){ $zip = zip_open($filename); if ($zip) { while ($zip_entry = zip_read($zip)) { $fp = fopen(zip_entry_name($zip_entry), "w"); if (zip_entry_open($zip, $zip_entry, "r")) { $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); fwrite($fp,"$buf"); zip_entry_close($zip_entry); fclose($fp); } } zip_close($zip); } } It works, but unfortunatelly the extracted files are all placed into the directory where the php file is located. Not where the original zip file was found. I tried to add the directory to fwrite, but without success. Does somebody know where to specify the target directory? Thank you for any help, Merlin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multiple return statements in a function.
On Thu, 2009-04-23 at 10:14 -0400, tedd wrote: > At 2:19 PM +0100 4/23/09, Tony Marston wrote: > >"tedd" wrote in message > > > It's called "Structured programming" -- one way in and one way out of a > >> function. > >> > >> There are, of course, exceptions where it might help others reviewing your > >> code to see what's going on, such as returning a null value if the > >> argument(s) provided are not suitable. But normally the rule is, do not > >> provide an exit from a function in more than one place. > > > >There is no such "rule", it is a matter of personal preference. As a > >previous poster has already said, if you want to leave a function early and > >ignore all subsequent processing it is easier to understand if you return > >immediately rather than have a mechanism to jump over the remaining code to > >a single return point. In the good old days we used to use the GOTO in COBOL > >to jump to the exit point, but then people found a way to abuse GOTO in very > >imaginatve ways. > > > >> The "benefit" is easier to read code. > > > >I think that an immediate return is easier to read, but what do I know - > >I've only been programming for 30 years. > > > >-- > >Tony Marston > > Tony: > > Don't get your panties in a knot. :-) > > I have 44 years of programming under my belt, so what? However, I > wish I could remember everything I learned during that time. > > But what I do remember is there's a school of thought called > "Structured Programming" that has a doctrine in which every function > should have only one entry and exit point. > > Now maybe you want to argue with that concept, that's fine -- but the > point remains this is a "rule" under "Structured Programming". That's > history. > > Now, I usually follow that rule for I have learned from experience > that in most cases, it is easier to read what is going on in a > function if you only have one exit. > > As I said in my post, there are of course exceptions. There are times > that requiring a function to have a single exit point will > unnecessarily create code that's hard to read -- so doing it > differently is something to consider in those cases. If you want to > have an immediate exit point in your functions and that makes your > code more readable, then that's fine and I'm not arguing that point. > > However, I am saying (after years of reading other people's code) it > is generally much easier to read code that follows "Structured > Programming" than it is to read code that doesn't. Actually I use an early return as much as possible also. If there are 5 conditions which disqualify the rest of the function from running then they'll all be listed one after the other at the top of the function. This way it's very easy to see exactly what doesn't qualify for evaluation. Additionally, it saves on the need for that many levels of indentation or making an overly complex conditional. I find it much more intuitive than mentally tracking several levels of indentation and scrolling to the bottom of the function. 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
Re: [PHP] checkboxes
At 10:11 AM -0400 4/23/09, PJ wrote: tedd wrote: > http://php1.net/a/edit-db-demo/ Here a user can search for a Last name, first name, or email. Note, there's no checkboxes because the user indicates what they are searching for by where they place their search criteria. HTH's tedd Thanks Tedd, Your demod uses javascript and I don't really want to use javascript. Apparently it is more open to hacking than just plain PHP/MySQL. ?? Also, I seem to have things going fairly well - it's a neat way to learn coding, especially when adjusting for things you hadn't planned in advance, like if the user forgets to enter data or doesn't click on the radio button. And then implementing the warnings and reloading (or not reloading the page) to keep the data entered upon omission or unacceptable entries. Get's hairy sometimes, but it's quite enlightening. ;-) Come-on, my demo uses a single javascript routine to ask the user IF they want to delete something. If javascript is turned off, my demo still works. This is just an example of enhancement with graceful degradation. It has nothing to do with the demo other than that. The point of my showing you the demo was to simply suggest that you forgo the checkboxes and go straight to the "Search" entry. After all, that tells you everything you want to know about what the user wants to do, right? Why have the user click a checkbox showing that they want to search for a book title and then also have then enter in the book title? Why not just have them enter the book title and be done with it? It might serve you well to rethink what you are wanting to do. 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
Re: [PHP] Multiple return statements in a function.
At 2:19 PM +0100 4/23/09, Tony Marston wrote: "tedd" wrote in message > It's called "Structured programming" -- one way in and one way out of a function. There are, of course, exceptions where it might help others reviewing your code to see what's going on, such as returning a null value if the argument(s) provided are not suitable. But normally the rule is, do not provide an exit from a function in more than one place. There is no such "rule", it is a matter of personal preference. As a previous poster has already said, if you want to leave a function early and ignore all subsequent processing it is easier to understand if you return immediately rather than have a mechanism to jump over the remaining code to a single return point. In the good old days we used to use the GOTO in COBOL to jump to the exit point, but then people found a way to abuse GOTO in very imaginatve ways. The "benefit" is easier to read code. I think that an immediate return is easier to read, but what do I know - I've only been programming for 30 years. -- Tony Marston Tony: Don't get your panties in a knot. :-) I have 44 years of programming under my belt, so what? However, I wish I could remember everything I learned during that time. But what I do remember is there's a school of thought called "Structured Programming" that has a doctrine in which every function should have only one entry and exit point. Now maybe you want to argue with that concept, that's fine -- but the point remains this is a "rule" under "Structured Programming". That's history. Now, I usually follow that rule for I have learned from experience that in most cases, it is easier to read what is going on in a function if you only have one exit. As I said in my post, there are of course exceptions. There are times that requiring a function to have a single exit point will unnecessarily create code that's hard to read -- so doing it differently is something to consider in those cases. If you want to have an immediate exit point in your functions and that makes your code more readable, then that's fine and I'm not arguing that point. However, I am saying (after years of reading other people's code) it is generally much easier to read code that follows "Structured Programming" than it is to read code that doesn't. 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
Re: [PHP] checkboxes
tedd wrote: > At 5:33 PM -0400 4/22/09, PJ wrote: >> Well, I'm making a page to do limited searching of the database. To keep >> it simple I just want to search by title, author, ISBN or copyright >> date. So, I need to input the user's choice, limit it to one of the >> options and pass the supplied parameter to the query. I prefer to not >> use Javascript. No need to disable stuff as that was merely a >> misdirected thought. I think Ashley's suggestion should work. My problem >> has been to understand the workings of the form inputs. Now, I'm just >> anticipating some acrobatic feats to be able to pass the author >> parameters to the query as they are comprised of two fields (first_name >> and last_name). But, I think that that can be done, at worst, by doing a >> different query just for the author. >> TIA. >> Phil > > > Phil: > > The user has to enter something in to do a search right? So why not > use what they enter as the type of search they what? > > Like so: > > http://php1.net/a/edit-db-demo/ > > Here a user can search for a Last name, first name, or email. Note, > there's no checkboxes because the user indicates what they are > searching for by where they place their search criteria. > > HTH's > > tedd Thanks Tedd, Your demod uses javascript and I don't really want to use javascript. Apparently it is more open to hacking than just plain PHP/MySQL. ?? Also, I seem to have things going fairly well - it's a neat way to learn coding, especially when adjusting for things you hadn't planned in advance, like if the user forgets to enter data or doesn't click on the radio button. And then implementing the warnings and reloading (or not reloading the page) to keep the data entered upon omission or unacceptable entries. Get's hairy sometimes, but it's quite enlightening. ;-) -- unheralded genius: "A clean desk is the sign of a dull mind. " - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multiple return statements in a function.
Richard Heyes wrote: > Hi, > >> while(true){ > > Yikes. > > Personally, I'd put the return value wherever it will make the code > easier to read. If you're checking what has been passed as arguments, > and one of them is wrong, I think there's little point in continuing, > so an immediate return is the order of the day. Well, I usually use that construct where I can have a number of different error-conditions - e.g. if I have a sequence of socket create, DNS lookup, bind, connect etc. /Per -- Per Jessen, Zürich (15.6°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multiple return statements in a function.
2009/4/23 Tony Marston : > > "tedd" wrote in message > news:p06240805c6161613a...@[192.168.1.101]... >> At 8:12 AM -0400 4/23/09, Peter van der Does wrote: >>>I tend to put my return value in a variable and at the end of the >>>function I have 1 return statement. >>>I have seen others doing returns in the middle of the function. >>> >>>-snip- >>> >>>What is your take? And is there any benefit to either method? >>> >>>Peter van der Does >> >> Peter: >> >> It's called "Structured programming" -- one way in and one way out of a >> function. >> >> There are, of course, exceptions where it might help others reviewing your >> code to see what's going on, such as returning a null value if the >> argument(s) provided are not suitable. But normally the rule is, do not >> provide an exit from a function in more than one place. > > There is no such "rule", it is a matter of personal preference. As a > previous poster has already said, if you want to leave a function early and > ignore all subsequent processing it is easier to understand if you return > immediately rather than have a mechanism to jump over the remaining code to > a single return point. In the good old days we used to use the GOTO in COBOL > to jump to the exit point, but then people found a way to abuse GOTO in very > imaginatve ways. > >> The "benefit" is easier to read code. > > I think that an immediate return is easier to read, but what do I know - > I've only been programming for 30 years. > > -- > Tony Marston > http://www.tonymarston.net > http://www.radicore.org > >> 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 > > As someone's who been playing this game for only 29 years, I like a single exit point. One of the issues I found with multiple exit points is that you have to work a little harder to guarantee a return. I always write my code so that if the function did nothing, then null or false are the return values ... function foo() { $result = False; // ... code which may or may nor affect $result return $result; } If your code is heavily nested (maybe an indicator that some refactoring is worth undertaking) and you introduce yet more code, keeping track of multiple exit points can be a little problematic. I suppose if you are the only developer then create a style and stick with it. Don't be afraid of refactoring your code if you feel that a different style is easier to work with. If you work in a team, then once the team has determined its style, stick with it. Even if it hurts. The hassle you'll get when your code doesn't "fit" is far more than the learning curve you'll go through getting the style. Richard. -- - Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multiple return statements in a function.
Hi, > while(true){ Yikes. Personally, I'd put the return value wherever it will make the code easier to read. If you're checking what has been passed as arguments, and one of them is wrong, I think there's little point in continuing, so an immediate return is the order of the day. Though with exceptions, this could be mitigated (IIRC). BTW there's also something to be said for code conciseness, which I think is loosely related. Eg your function could be condensed to this: function check($a) { return is_array($a) ? true : false; } But then the question is nullified somewhat. -- Richard Heyes HTML5 graphing: RGraph (www.rgraph.net) PHP mail: RMail (www.phpguru.org/rmail) PHP datagrid: RGrid (www.phpguru.org/rgrid) PHP Template: RTemplate (www.phpguru.org/rtemplate) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Suggestions of some good, simple file upload 'in progress' code?
At 1:46 PM -0600 4/22/09, scubak1w1 wrote: I am thinking that is where I am at... as you said, the user just needs to know that there computer is busy, hang on a second already! I like those icons - if I may be so bold though, and excuse the broadness of the question, are you / can you use some Javascript to display this as the file uploads? I am already using AJAX on the page/form so I guess I could add an icon to the page before I run the PHO to upload the file, yes? BUT I do appreciate all of the other suggestions, very muich - some weekend reading & experimenting I am thinking... :-) There's really no need for javascript. Just direct the user to a page that provides the upload and have that page show the "loading" gif. Look, make it easy on yourself. I could have saved a week, or more, of my life by taking that approach when I first thought of the question "What do I show the user while the file is uploading?" But no, I went the complete route of setting up communication between the client and server to track the upload -- that's not easy because php has no client-side functionality and javascript is prohibited from accessing the file information you need on the users machine (security concerns). So, it can't be done easily. But in the end, users are like clients, there's no need to explain in detail what you are doing -- just make whatever it is work AND look good and everything will be okey-dokey by them. To prove my point, the next time you see a good looking web site, try running it through the W3C validator. (http://validator.w3.org). If clients were concerned about things being done right, there would be a lot more web sites validating. 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
Re: [PHP] Multiple return statements in a function.
George Larson wrote: > That's an interesting subject that I've never considered. > > I usually return immediately. For me, it makes the code easier to > read. I work with a number of other coders here and, if the result > isn't returned then I have to keep reading through the code to make > sure nothing else is done with it. However, when I see the 'return' > then I know we're done there. I tend to try to have just one return point, but I will occasionally have more, typically when a function returns more than just true or false. If it's a true or false outcome, but I still have multiple failure points, I'll sometimes use a construct like this: rc=0; while(true){ if ( cond1 ) { errormsg; rc=1; break; } if ( cond2 ) { errormsg; rc=1; break; } if ( cond3 ) { errormsg; rc=1; break; } if ( cond4 ) { errormsg; rc=1; break; } if ( cond5 ) { errormsg; rc=1; break; } if ( cond6 ) { errormsg; rc=1; break; } if ( cond7 ) { errormsg; rc=1; break; } break; } return rc; -- Per Jessen, Zürich (16.6°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multiple return statements in a function.
"tedd" wrote in message news:p06240805c6161613a...@[192.168.1.101]... > At 8:12 AM -0400 4/23/09, Peter van der Does wrote: >>I tend to put my return value in a variable and at the end of the >>function I have 1 return statement. >>I have seen others doing returns in the middle of the function. >> >>-snip- >> >>What is your take? And is there any benefit to either method? >> >>Peter van der Does > > Peter: > > It's called "Structured programming" -- one way in and one way out of a > function. > > There are, of course, exceptions where it might help others reviewing your > code to see what's going on, such as returning a null value if the > argument(s) provided are not suitable. But normally the rule is, do not > provide an exit from a function in more than one place. There is no such "rule", it is a matter of personal preference. As a previous poster has already said, if you want to leave a function early and ignore all subsequent processing it is easier to understand if you return immediately rather than have a mechanism to jump over the remaining code to a single return point. In the good old days we used to use the GOTO in COBOL to jump to the exit point, but then people found a way to abuse GOTO in very imaginatve ways. > The "benefit" is easier to read code. I think that an immediate return is easier to read, but what do I know - I've only been programming for 30 years. -- Tony Marston http://www.tonymarston.net http://www.radicore.org > 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
Re: [PHP] Multiple return statements in a function.
On Thu, Apr 23, 2009 at 08:12:47AM -0400, Peter van der Does wrote: > I tend to put my return value in a variable and at the end of the > function I have 1 return statement. > I have seen others doing returns in the middle of the function. > > Example how I do it: > function check($a) { > $return=''; > if ( is_array( $a ) ) { > $return='Array'; > } else { > $return='Not Array'; > } > return $return; > } > > Example of the other method: > function check($a) { > > if ( is_array( $a ) ) { > return ('Array'); > } else { > return ('Not Array'); > } > } > > What is your take? And is there any benefit to either method? As mentioned, this is a matter of style. However, in a lot of cases, in order to get the return at the very end, it's necessary to put endless if/else pairs in the function. That makes it hard to read the source. I'm sure there are purists out there who would insist the single return go at the end. But expediency and readability may dictate otherwise. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] MySQL -- finding whether there's a transaction started
Hello list, I'm developing a library and would need to know if the code calling my library has already started a MySQL transaction or not. I want to know whether I should start one or use savepoints instead -- starting a transaction if one is already in progress commits the existing transaction, and setting a savepoint silently fails outside transactions. And I was unable to find any non-destructive way of retrieving that information -- is there any? Thank you, Bogdan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multiple return statements in a function.
At 8:12 AM -0400 4/23/09, Peter van der Does wrote: I tend to put my return value in a variable and at the end of the function I have 1 return statement. I have seen others doing returns in the middle of the function. -snip- What is your take? And is there any benefit to either method? Peter van der Does Peter: It's called "Structured programming" -- one way in and one way out of a function. There are, of course, exceptions where it might help others reviewing your code to see what's going on, such as returning a null value if the argument(s) provided are not suitable. But normally the rule is, do not provide an exit from a function in more than one place. The "benefit" is easier to read code. 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
Re: [PHP] checkboxes
At 5:33 PM -0400 4/22/09, PJ wrote: Well, I'm making a page to do limited searching of the database. To keep it simple I just want to search by title, author, ISBN or copyright date. So, I need to input the user's choice, limit it to one of the options and pass the supplied parameter to the query. I prefer to not use Javascript. No need to disable stuff as that was merely a misdirected thought. I think Ashley's suggestion should work. My problem has been to understand the workings of the form inputs. Now, I'm just anticipating some acrobatic feats to be able to pass the author parameters to the query as they are comprised of two fields (first_name and last_name). But, I think that that can be done, at worst, by doing a different query just for the author. TIA. Phil Phil: The user has to enter something in to do a search right? So why not use what they enter as the type of search they what? Like so: http://php1.net/a/edit-db-demo/ Here a user can search for a Last name, first name, or email. Note, there's no checkboxes because the user indicates what they are searching for by where they place their search criteria. HTH's 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
Re: [PHP] Multiple return statements in a function.
On Thu, Apr 23, 2009 at 8:25 AM, Per Jessen wrote: > Peter van der Does wrote: > >> I tend to put my return value in a variable and at the end of the >> function I have 1 return statement. >> I have seen others doing returns in the middle of the function. >> >> Example how I do it: >> function check($a) { >> $return=''; >> if ( is_array( $a ) ) { >> $return='Array'; >> } else { >> $return='Not Array'; >> } >> return $return; >> } >> >> Example of the other method: >> function check($a) { >> >> if ( is_array( $a ) ) { >> return ('Array'); >> } else { >> return ('Not Array'); >> } >> } >> >> What is your take? And is there any benefit to either method? > > It's only about style and coding logic. In essence, all the return does > is pop the previous IP off the stack and adjust the stack pointer. It > doesn't matter where you do that. > > > /Per > > > -- > Per Jessen, Zürich (16.2°C) > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > That's an interesting subject that I've never considered. I usually return immediately. For me, it makes the code easier to read. I work with a number of other coders here and, if the result isn't returned then I have to keep reading through the code to make sure nothing else is done with it. However, when I see the 'return' then I know we're done there. That said, I often see questionable coding practices in use at work. I follow this list (and try to read books about the technologies I use) because I intend to develop good practices for myself. That in mind, if anybody feels strongly about doing it the other way, I'd be interested in understanding its benefits. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Unable to send mail from PHP to AT&T e-mail address
From: Chris Any light anyone can throw on the 'nob...@myserver.com' address would be most welcome. >>> >>> It is using the apache user @ your host name as the default. Try this: >>> >>> ini_set('sendmail_from', 'whate...@wherever.com'); >> >> I will try this but I do not understand why it should work. I have a >> 'From:...' entry in my headers. Why is this not being used as the >> primary from address and why is 'nob...@myserver.com' being added >> instead as the first from address ? In other words, I can understand if >> I supply no 'From:...' header entry that a default 'nob...@myserver.com' >> would be used but I do not understand why it is used even when I supply >> a 'From:...' header entry. >> > > "From: " is used by your mail client to show who it's from. > > the ini_set (or you can set the 5th param to the mail() function) is a > return-path. If the message bounces (recipient's mailbox full, server > down, whatever the reason) it gets delivered to that address. They serve > different purposes. The dirty little secret that nobody seems to know is that the RFCs reserve Return-path for use by the MTA servers. It can be replaced by any of them in the routing chain and is used when mail crosses into or out of SMTP networks. If you want a return address other than From to stick all the way through, you have to use the Reply-to and/or Sender headers. Bob McConnell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multiple return statements in a function.
Peter van der Does wrote: > I tend to put my return value in a variable and at the end of the > function I have 1 return statement. > I have seen others doing returns in the middle of the function. > > Example how I do it: > function check($a) { > $return=''; > if ( is_array( $a ) ) { > $return='Array'; > } else { > $return='Not Array'; > } > return $return; > } > > Example of the other method: > function check($a) { > > if ( is_array( $a ) ) { > return ('Array'); > } else { > return ('Not Array'); > } > } > > What is your take? And is there any benefit to either method? It's only about style and coding logic. In essence, all the return does is pop the previous IP off the stack and adjust the stack pointer. It doesn't matter where you do that. /Per -- Per Jessen, Zürich (16.2°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Multiple return statements in a function.
I tend to put my return value in a variable and at the end of the function I have 1 return statement. I have seen others doing returns in the middle of the function. Example how I do it: function check($a) { $return=''; if ( is_array( $a ) ) { $return='Array'; } else { $return='Not Array'; } return $return; } Example of the other method: function check($a) { if ( is_array( $a ) ) { return ('Array'); } else { return ('Not Array'); } } What is your take? And is there any benefit to either method? -- Peter van der Does GPG key: E77E8E98 Blog: http://blog.avirtualhome.com Forums: http://forums.avirtualhome.com Jabber ID: pvanderd...@gmail.com GetDeb Package Builder http://www.getdeb.net - Software you want for Ubuntu -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] ! and !=
On 23 April 2009 01:05, George Langley advised: > Doh, of course! Just not thinking about the scope of > the operator. If $var1 = 1, then !$var1 = 0 > Thanks everyone! Well, actually, to be strictly accurate, since ! is a Boolean operator, if $var1 = 1 then !$var1 = FALSE. Cheers! Mike -- Mike Ford, Electronic Information Developer, C507, Leeds Metropolitan University, Civic Quarter Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.f...@leedsmet.ac.uk Tel: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php