php-general Digest 2 Jul 2012 11:59:05 -0000 Issue 7874 Topics (messages 318359 through 318361):
Re: Hello again 318359 by: tamouse mailing lists Re: php form action breaks script 318360 by: Ford, Mike Destructor not called when extending SimpleXMLElement 318361 by: Nick Chalk Administrivia: To subscribe to the digest, e-mail: php-general-digest-subscr...@lists.php.net To unsubscribe from the digest, e-mail: php-general-digest-unsubscr...@lists.php.net To post to the list, e-mail: php-gene...@lists.php.net ----------------------------------------------------------------------
--- Begin Message ---On Sun, Jul 1, 2012 at 6:21 PM, RGraph.net support <supp...@rgraph.net> wrote: > Just thought I'd say hello again. Back to brush up on my PHP a little > after a bit of a break - more reading than replying I'd imagine. I > have some pretty bad jokes too that I might surreptitiously insert > here and there... Welcome back. Friday is mainly the free-for-all day (philosophical questions, puns, jokes)
--- End Message ---
--- Begin Message ---> -----Original Message----- > From: Tim Dunphy [mailto:bluethu...@gmail.com] > Sent: 28 June 2012 01:18 > > Hey guys, > > It's been a little while since I've toyed with this, and I hope you > don't mind my coming back to you for some more advice. But I've > enjoyed some limited success with David R's advice regarding adding > some strong quoting to the mix. Here is what I last tried - > > <form method="post" action="' . $_SERVER['[PHP_SELF'] .'"> Wow! That's completely wacko! (OK, just looked at the full code and seen it's in the middle of a single-quoted echo, so it's not that bad after all :). You've got a spare [ in there -- the notice saying Undefined index: [PHP_SELF should have alerted you to this, as the index you want is just plain PHP_SELF. <form method="post" action="' . $_SERVER['PHP_SELF'] .'"> > The pages do work, and the form checking code does its job (empty > text > displays what information is missing). Except that there is an > annoying message that appears on screen and in the logs - > > Notice: Undefined index: subject in > /Library/WebServer/Documents/examples/ch03/final/makemeelvis/sendema > il.php > on line 23 Notice: Undefined index: elvismail in > /Library/WebServer/Documents/examples/ch03/final/makemeelvis/sendema > il.php > on line 24 Notice: Undefined index: [PHP_SELF in > /Library/WebServer/Documents/examples/ch03/final/makemeelvis/sendema > il.php > on line 62 Looking at the relevant bit of your script (assume this is line 23 onward): > $subject = $_POST['subject']; > $text = $_POST['elvismail']; > $output_form = "false"; > > > if (isset($_POST['Submit'])) { You're accessing $_POST['subject'] and $_POST['elvismail'] *before* the check to see if this is a from a form submission - on the initial access, to just display the form, these $_POST indexes will not be set so causing the notices. You either need to put the assignments inside the if (isset($POST['Submit'])) branch, or conditionalise them in some way, such as: $subject = isset($_POST['subject']) ? $_POST['subject'] : NULL; $text = isset($_POST['elvismail']) ? $_POST['elvismail'] : NULL; Another oddity in your script is that you're using the string values "true" and "false" instead of the Boolean true and false. Because of the way PHP typecasts, both "true" and "false" are actually regarded as Boolean true, which could get a little confusing -- so it's much better (and probably more efficient) to use the proper Boolean values. Also, it enables your later test to be written, with confidence, as just if ($output_form) { Also, also, with a little bit of rearrangement of the tests, you can reduce the amount of code a bit: if (!empty($subject) && !empty($text)) { // Both inputs supplied -- good to go. $output_form = false; } else { // At least one input missing -- need to redisplay form $output_form = true; if (empty($subject)) { if (empty($text)) { echo 'You forgot the email subject and body.<br />'; } else { echo 'You forgot the email subject.<br />'; } } else { echo 'You forgot the email body text.<br />'; } } Actually, I think my inclination would be to assign $output_form first, and then do the rest of the tests: $output_form = empty($subject) || empty($text); if ($output_form) { // At least one input missing -- work out which one if (empty($subject)) if (empty($text)) { echo 'You forgot the email subject and body.<br />'; } else { echo 'You forgot the email subject.<br />'; } } else { echo 'You forgot the email body text.<br />'; } } That said, there are lots of personal preferences involved here, and I'm sure others would offer different possibilities. (Me personally, I also prefer the alternative block syntax with initial : and end... tags -- but then, the forests of curly braces others seem to find acceptable make my eyes go fuzzy, so go figure....) Cheers! Mike -- Mike Ford, Electronic Information Developer, Libraries and Learning Innovation, Portland PD507, City Campus, Leeds Metropolitan University, Portland Way, LEEDS, LS1 3HE, United Kingdom E: m.f...@leedsmet.ac.uk T: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm
--- End Message ---
--- Begin Message ---Afternoon all. I seem to be having a little trouble with extending the SimpleXMLElement class. I would like to add a destructor to the subclass, but am finding that it is not called. Attached is a minimal demonstration of the problem. The XMLConfig class extends SimpleXMLElement, and its destructor is not called. The XMLConfig2 class, which does not use inheritance, does have its destructor called. The test platform is CentOS 6.2, with PHP version 5.3.3. What am I missing? Thanks for your help. Nick. -- Nick Chalk. Loadbalancer.org Ltd. Phone: +44 (0)870 443 8779 http://www.loadbalancer.org/<<attachment: minimal_test.php>>
--- End Message ---