php-general Digest 2 Feb 2009 15:22:12 -0000 Issue 5936
php-general Digest 2 Feb 2009 15:22:12 - Issue 5936 Topics (messages 287518 through 287538): Re: [PHP-QA] problem code 287518 by: David Swenson PHP Linux/Windows Outlook 2003 HTML email problem 287519 by: German Geek 287520 by: Chris Re: PHP Enclosing Tags? Do You Close Your PHP Declarations? 287521 by: Yannick Mortier check public key of SSL client certificate 287522 by: Serge Re: Payment question in Canada 287523 by: Edmund Hertle Includes only if required? 287524 by: Edmund Hertle 287526 by: Richard Heyes 287531 by: Eric Butera Re: More questions about SESSION use 287525 by: Edmund Hertle Boolean Assignment Operator 287527 by: Gavin Hodge 287528 by: Edmund Hertle 287529 by: Gavin Hodge 287530 by: Robert Cummings 287532 by: Robert Cummings 287533 by: Eric Butera 287534 by: Edmund Hertle 287535 by: Gavin Hodge 287536 by: Steven Buehler Re: Switch statement Question 287537 by: Frank Stanovcak Re: Weird url passing what does it mean, am I hacked? 287538 by: clive 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 -- ---BeginMessage--- ~CODE~~~ $x_Message = $x_fname. .$x_lname. .$_practice. just registered for .$x_nevent.Method of payment .$x_payment. Email address is.$x_email. Telephone number.$x_tele. Question is .$x_qanda.; ~/CODE~~ Recheck your code for syntax error. Appears you have one to few/many quotes (). Good Luck David On Sun, Feb 1, 2009 at 14:08, Chris Ives ch...@ives.bz wrote: What is wrong with this code? $x_Message = $x_fname. .$x_lname. .$_practice. just registered for .$x_nevent.Method of payment .$x_payment. Email address is.$x_email. Telephone number.$x_tele. Question is .$x_qanda.; $message = $x_Message; $from = $x_email; $to = nci...@gmail.com; $subject = Panorama Registration; $headers = From: $from; /* Now we are ready to send the email so we call php's mail() function with the appropriate variables from above included in the brackets */ mail($to,$subject,$message,$headers); -- PHP Quality Assurance Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php -- /Daniel P. Brown daniel.br...@parasane.net || danbr...@php.net http://www.parasane.net/ || http://www.pilotpig.net/ Unadvertised dedicated server deals, too low to print - email me to find out! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php No virus found in this incoming message. Checked by AVG. Version: 7.5.552 / Virus Database: 270.10.16/1928 - Release Date: 1/31/2009 8:03 PM No virus found in this outgoing message. Checked by AVG. Version: 7.5.552 / Virus Database: 270.10.16/1928 - Release Date: 1/31/2009 8:03 PM ---End Message--- ---BeginMessage--- Hi All, We've got a problem with our Ubuntu Linux machine sending HTML emails to Outlook 2003: It's an Ubuntu Server (uname -a Linux CDR2-221 2.6.24-19-server #1 SMP Wed Jun 18 15:18:00 UTC 2008 i686 GNU/Linux) with the newest version of Postfix installed as the Mail server. Unfortunately, all emails sent as HTML, using the PEAR library for sending email like so: public static function sendEmail($fromEmail, $recipientsEmails, $subject, $txtBody, $htmlBody = null, $ccEmails = null) { require_once 'Mail.php'; require_once 'Mail/mime.php'; $message = new Mail_mime(); $message-setTXTBody($txtBody); if (!$htmlBody) $htmlBody = str_replace(\n, br /\n, $txtBody); $message-setHTMLBody($htmlBody); $message-setFrom($fromEmail); if ($ccEmails) { if (!is_array($ccEmails)) $ccEmails = array($ccEmails); foreach ($ccEmails as $cc) { $message-addCc($cc); } } //$message-addCc(m...@insiteorg.com); $message-setSubject($subject); $body = $message-get(); $headers = $message-headers(); $mail = Mail::factory(mail); if (!is_array($recipientsEmails)) $recipientsEmails = array($recipientsEmails); foreach ($recipientsEmails as $mailto) { $mail-send($mailto, $headers, $body); } } arrive with only the plaintext part in Outlook 2003 (and only in Outlook 2003). All other email programs (Outlook 2007 e.g.) seem to work fine with the formatting. This only started happening on the Linux machine and works fine when emails are sent by a windows host or another mail server from the ISP. So i suspect it must be the setup of Postfix on that machine that is not quite correct. Other than that, i get the following messages from PHP, apparently the PEAR library has some (strinct)
Re: [PHP] Re: Switch statement Question
tedd tedd.sperl...@gmail.com wrote in message news:p06240801c5aa0ed7d...@[192.168.1.101]... At 4:16 PM +0100 1/30/09, Jochem Maas wrote: tedd schreef: At 4:43 PM -0500 1/29/09, Frank Stanovcak wrote: yes...that is legal. as long as the statment resolves to a boolean it will work. It's not technically correct, but it does work. There you go again. What's technically correct? hiya tedd, you mean to ask not technically correct ... I plead that it's his statement that is not technically correct. 1. php does a soft comparison ('==' rather than '===') so the results of each case expression is auto-cast to a boolean (in the case of switch'ing on TRUE), ergo there is no 'as long', statements will always resolve to a boolean ... only they may not do it in a way that is readily understood by everyone. 2. the php engine specifically allows for 'complex expression' cases testing against a boolean switch value ... not best practice according to some but very much technically correct according to the php implementation. Good explanation -- I think the drum he's beating is that some of use the switch without actually using the main expression within the control, such as: switch($who_cares) { case $a = $b: // do something break; case $a 0: // do something else break; case $a 0: // do something elser break; } The control works. However to him, technically correct means: switch($a) { case 0: // do something break; case 1: // do something else break; case 2: // do something elser break; } That's what I think he's advocating. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com very true since this is the way it is taught in every book. Php, however, allows for other uses that weren't technically in the original plan for this command from other languages. The problem is I shave my head, so I have no hairs to split over this one. :) Frank -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Weird url passing what does it mean, am I hacked?
If your using firefox, are you sure its not some addon, does this URL appear in the HTML source? Clive Terion Miller wrote: I noticed yesterday that sometimes I was seeing a strange url passing at the bottom of the browser when clicking around my site I'm working on while watching the page loads, its calling to mouserunner.com and I went to the site and it is a bunch of links, my site is on a private server for a large media company, clues on what this means and where to look to stop it, what's it doing scraping my site or something? Thanks folks... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Boolean Assignment Operator
-Original Message- From: farn...@googlemail.com [mailto:farn...@googlemail.com] On Behalf Of Edmund Hertle Sent: Monday, February 02, 2009 7:03 AM To: Gavin Hodge Cc: php-general@lists.php.net Subject: Re: [PHP] Boolean Assignment Operator 2009/2/2 Gavin Hodge gavin.ho...@gmail.com Hi, I'm fairly new to PHP, having migrated from the Java / C# world. I wrote some code similar to the following: $success = true; $success = operation1(); $success = operation2(); if ($success === true) { operation3(); // depends on 1 and 2 being successful } This didn't work as expected. After a bit of digging I found: * The = operation isn't mentioned anywhere in the PHP documentation * The = function seems to work as expected, however the following is observed... $success = true; $success = true; print $success == true; // outputs 1 print $sucesss === true; // no output * The 'or' assignment operator |= causes no errors but doesn't work. Can any PHP gurus explain why the = operator works at all, and why === seems to fail afterwards? Cheers, Gavin. Hey, never heard of the |= operator. So I think php does not support it. I cannot say how = works in Java or C# but as of php it works like that (IMO) (reference instead of copy): $var1 = test1; $var2 = $var1; $var3 = $var1; $var1 = test2; echo $var1; // test2 echo $var2; // test1 echo $var3; // test2 Actually, if you run your test, $var3 does NOT come out as test2, it will return a 0 for that echo statement. To get the results you want, it needs to be: $var3 = $var1; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: More questions about SESSION use
Show the code where your session vars are written and I would prefer using isset() instead of empty() if you want to check if this var is set or not. -eddy Hi All, here is the index page where users login and the sessions are set: ?php //start session session_start(); //db connection include include(inc/dbconn_open.php) ; //errors on error_reporting(E_ALL); ini_set('display_errors', '1'); if (!empty($_POST['UserName']) !empty($_POST['Password'])) { $UserName = $_POST['UserName']; $Password = $_POST['Password']; } $msg = ''; if (!empty($UserName)) { $sql = SELECT `AdminID`,`UserName` FROM `admin` WHERE `UserName`='$UserName' and`Password`='$Password'; $result = mysql_query ($sql); $row = mysql_fetch_object ($result); If (mysql_num_rows($result) 0) { $_SESSION['AdminLogin'] = true; $_SESSION['user'] = $UserName; $_SESSION['AdminID'] = $row-AdminID; header ('Location: Main.php'); exit; } else { $msg = Sorry You Entered An Invalid LoginbrPlease Try AgainbrClick to Contact a href='mailto:b...@blahblah.com'bblah blah/b/a If You Need Help; } } //include (VariableReveal2.php); ?
Re: [PHP] Blank page of hell..what to look for
On Feb 2, 2009, at 12:02 PM, Terion Miller wrote: Is there a certain thing that should be suspected and looked at first when getting the php blank page of hell I have errors on and nothing is being output anywhere to lead me in the right direction, I have a VariableReveal script (one of you provide and THANK YOU IT HAS BEEN A LIFESAVER) But it is doing nothing today, yesterday the page worked today I get the blank page with not a clue in sight ARGH... What I typically do with that is make sure that if you are using HEREDOC you don't have any extra spaces after the opening or closing HEREDOC statements. Also, I have gone through and put just: echo 1; echo 2; etc through out the code to see if i could pin down exactly WHERE the problem was starting... It help to narrow it down. What might help is if it's a small script, go ahead and post it to the list and maybe we can find something quickly. -- Jason Pruim japr...@raoset.com 616.399.2355
Re: [PHP] Blank page of hell..what to look for
I have errors on Including E_NOTICE ? -- Richard Heyes HTML5 Graphing for Firefox, Chrome, Opera and Safari: http://www.rgraph.org (Updated January 31st) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Blank page of hell..what to look for
I just use error_reporting(E_ALL); that would include the E_NOTICE right? On Mon, Feb 2, 2009 at 11:27 AM, Richard Heyes rich...@php.net wrote: I have errors on Including E_NOTICE ? -- Richard Heyes HTML5 Graphing for Firefox, Chrome, Opera and Safari: http://www.rgraph.org (Updated January 31st)
Re: [PHP] Blank page of hell..what to look for
Terion Miller wrote: Is there a certain thing that should be suspected and looked at first when getting the php blank page of hell I have errors on and nothing is being output anywhere to lead me in the right direction, I have a VariableReveal script (one of you provide and THANK YOU IT HAS BEEN A LIFESAVER) But it is doing nothing today, yesterday the page worked today I get the blank page with not a clue in sight ARGH... Terion More then likely it is a parse error within the page. And no matter what error reporting you have turned on within the script will effect the outcome. You have two choices. Turn on error reporting from apache using the httpd.conf file, in your php.ini file, or with a .htaccess file. This is the only way to get around parse errors without having error reporting turned on globally. The other way is to cut/paste your code into sections. Cut out a large chunk of it, see if it works, if it does, paste it back in and remove a smaller chunk, rinse/repeat until your find the error of your ways... :) Better yet, use a IDE the does code highlighting. This would point you to the problem rather quickly. -- Jim Lucas Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them. Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] IP to location / XML
Hi there, I want do discover the location from a IP, I use this url ' http://www.onflex.org/geo/xml/ ', that's does a XML file, it's ok on my browser, but when i try to read this file with php: $myxml = simplexml_load_file ('http://www.onflex.org/geo/xml/'); That's gives a error: Warning: simplexml_load_file() [function.simplexml-load-file]: http://www.onflex.org/geo/xml/:8: parser error : Input is not proper UTF-8, indicate encoding ! Bytes: 0xE3 0x6F 0x20 0x50 * Anyone Who might help me with this? zechim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RES: IP to location / XML
Hi Nathan, i'll try max minds geo ip, that's what i want. -Mensagem original- De: Nathan Rixham [mailto:nat...@gmail.com] Enviada em: segunda-feira, 2 de fevereiro de 2009 16:13 Para: php-general@lists.php.net; Jônatas Zechim Cc: 'PHP General' Assunto: Re: IP to location / XML Jônatas Zechim wrote: Hi there, I want do discover the location from a IP, I use this url ' http://www.onflex.org/geo/xml/ ', that's does a XML file, it's ok on my browser, but when i try to read this file with php: $myxml = simplexml_load_file ('http://www.onflex.org/geo/xml/'); That's gives a error: Warning: simplexml_load_file() [function.simplexml-load-file]: http://www.onflex.org/geo/xml/:8: parser error : Input is not proper UTF-8, indicate encoding ! Bytes: 0xE3 0x6F 0x20 0x50 * Anyone Who might help me with this? zechim try this: $file = get_file_contents('http://www.onflex.org/geo/xml/'); $file = utf8_decode($file); $myxml = simplexml_load_string($file); the above assumes the problem is because the file is really latin-1 quick note, using the service at onflex.org will always return you're servers ip address not the end users (as you're calling from server not clients browser) if this is what you want great, if not then you may want to try max minds geo ip. regards! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Blank page of hell..what to look for
Terion Miller webdev.ter...@gmail.com wrote in message news:37405f850902020902j624356ccp4ea869bc45161...@mail.gmail.com... Is there a certain thing that should be suspected and looked at first when getting the php blank page of hell I have errors on and nothing is being output anywhere to lead me in the right direction, I have a VariableReveal script (one of you provide and THANK YOU IT HAS BEEN A LIFESAVER) But it is doing nothing today, yesterday the page worked today I get the blank page with not a clue in sight ARGH... Terion I'm not sure what your setup is, but I get this frequently when testing on my windows server with IE What I do to get the error is save a blank page over the one that is causing the problem. Load it in the browser, then resave the probelem code, and refresh. I almost always end up having left off a ; or } somewhere, and it just won't report it till I refresh like this. Hope that helps. Frank. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Blank page of hell..what to look for
Terion Miller a écrit : Is there a certain thing that should be suspected and looked at first when getting the php blank page of hell Did you check error logs from Apache or the one you configured in php.ini ? -- Mickaël Wolff aka Lupus Michaelis http://lupusmic.org Seeking for a position http://lupusmic.org/pro/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Boolean Assignment Operator
It actually will return FATAL ERROR or something like that since you didn't echo'ed variables or string ;) On Mon, Feb 2, 2009 at 3:03 PM, Edmund Hertle edmund.her...@student.kit.edu wrote: 2009/2/2 Gavin Hodge gavin.ho...@gmail.com Hi, I'm fairly new to PHP, having migrated from the Java / C# world. I wrote some code similar to the following: $success = true; $success = operation1(); $success = operation2(); if ($success === true) { operation3(); // depends on 1 and 2 being successful } This didn't work as expected. After a bit of digging I found: * The = operation isn't mentioned anywhere in the PHP documentation * The = function seems to work as expected, however the following is observed... $success = true; $success = true; print $success == true; // outputs 1 print $sucesss === true; // no output * The 'or' assignment operator |= causes no errors but doesn't work. Can any PHP gurus explain why the = operator works at all, and why === seems to fail afterwards? Cheers, Gavin. Hey, never heard of the |= operator. So I think php does not support it. I cannot say how = works in Java or C# but as of php it works like that (IMO) (reference instead of copy): $var1 = test1; $var2 = $var1; $var3 = $var1; $var1 = test2; echo var1; // test2 echo var2; // test1 echo var3; // test2
[PHP] pear:Auth invalid username/password
I'm using Pear Auth on several sites and am looking for suggestions on the best way to implement error reporting on a failed log-in. Currently I'm using a function that checks if the posted username is in the users table...and if the password is a match. Auth logs the user on if so...but if not it takes manually running the queries to generate the right failure message. Is there a cleaner way using error messages generated by the getAuth() method or another method in the Auth class? I didn't see anything in the docs...but it seems like an obvious bit of functionailty I would sort of expect it to be included. Anyone know of such a thing? John Corry
Re: [PHP] pear:Auth invalid username/password
John Corry wrote: I'm using Pear Auth on several sites and am looking for suggestions on the best way to implement error reporting on a failed log-in. Currently I'm using a function that checks if the posted username is in the users table...and if the password is a match. Auth logs the user on if so...but if not it takes manually running the queries to generate the right failure message. You mean if it's a valid username but not password? I'd say don't. While it's a little nicer for your users (hey, your password was wrong) - it's also a lot easier for attackers. Hmm, that means it's a valid user, lets see if we can brute force the password. Username or password are incorrect - an attacker has no idea which bit is wrong. You could force a user to use their email address as their username to make it easier to remember. Depends on the app audience I guess, if it's an internal only app - go with #1 (no idea about Pear Auth though), if it's public, there's no way I'd say your password is wrong, just provide a forgot password feature. -- 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] Re: More questions about SESSION use
Edmund Hertle wrote: 2009/2/1 Terion Miller webdev.ter...@gmail.com This is how it was originally written: if (empty($_SESSION['AdminLogin']) || $_SESSION['AdminLogin'] != true){ header (Location: LogOut.php); $_SESSION['user']=$UserName; $_SESSION['AdminID']=$AdminID; --*I added this one originally the script only used 'user' and 'AdminLogin'* but passed them in urls } Those two lines after header() will not be executed. Yes they will because there is no 'exit'. Header is just a function call, if you want to stop processing you have to do it yourself. -- 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] Includes only if required?
On Mon, Feb 2, 2009 at 6:42 AM, Edmund Hertle farn...@googlemail.com wrote: Hey, normally I prefer to do all my includes (classes + config files) at the beginning if my php files. But recently I thought about including some classes only if they are needed later in my code (like pear Mail and Mail_mime only if an e-mail is about to be sent) because of speed issues. So my question: Is this something I should consider? Or is it something I normally will not notice? -eddy Look at spl_autoload_register. -- http://www.voom.me | EFnet: #voom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Includes only if required?
Hey, normally I prefer to do all my includes (classes + config files) at the beginning if my php files. But recently I thought about including some classes only if they are needed later in my code (like pear Mail and Mail_mime only if an e-mail is about to be sent) because of speed issues. So my question: Is this something I should consider? Or is it something I normally will not notice? -eddy
Re: [PHP] Boolean Assignment Operator
On Mon, Feb 2, 2009 at 7:49 AM, Gavin Hodge gavin.ho...@gmail.com wrote: Hi, I'm fairly new to PHP, having migrated from the Java / C# world. I wrote some code similar to the following: $success = true; $success = operation1(); $success = operation2(); if ($success === true) { operation3(); // depends on 1 and 2 being successful } This didn't work as expected. After a bit of digging I found: * The = operation isn't mentioned anywhere in the PHP documentation * The = function seems to work as expected, however the following is observed... $success = true; $success = true; print $success == true; // outputs 1 print $sucesss === true; // no output * The 'or' assignment operator |= causes no errors but doesn't work. Can any PHP gurus explain why the = operator works at all, and why === seems to fail afterwards? Cheers, Gavin. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php http://us.php.net/manual/en/language.operators.bitwise.php You're doing an AND, then assigning it when you say =. Think of it like doing something such as .= or +=. You might also be confusing = with = where = means assign by reference. This used to be very necessary when dealing with php4 oop, but isn't so much anymore. -- http://www.voom.me | EFnet: #voom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Includes only if required?
Hi, Mail_mime Ooh... only if an e-mail is about to be sent) because of speed issues. So my question: Is this something I should consider? Or is it something I normally will not notice? Depends on the load on your server. If you're getting a billion requests per second, then it may well be cause for concern. Either way you can define a function called __autoload that gets called when a class is about to be instantiated. This function can then load the correct library. On demand as it were. http://uk2.php.net/__autoload -- Richard Heyes HTML5 Graphing for Firefox, Chrome, Opera and Safari: http://www.rgraph.org (Updated January 31st) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: More questions about SESSION use
2009/2/1 Terion Miller webdev.ter...@gmail.com This is how it was originally written: if (empty($_SESSION['AdminLogin']) || $_SESSION['AdminLogin'] != true){ header (Location: LogOut.php); $_SESSION['user']=$UserName; $_SESSION['AdminID']=$AdminID; --*I added this one originally the script only used 'user' and 'AdminLogin'* but passed them in urls } Those two lines after header() will not be executed. Hi David, yes I have session_start(); on everypage very 1st line. terio Show the code where your session vars are written and I would prefer using isset() instead of empty() if you want to check if this var is set or not. -eddy
Re: [PHP] PHP Enclosing Tags? Do You Close Your PHP Declarations?
On Mon, 2 Feb 2009 08:23:49 +0100, Yannick Mortier mvmort...@googlemail.com wrote: 2009/2/2 Alpár Török torokal...@gmail.com: 2009/2/1 Yannick Mortier mvmort...@googlemail.com I once read that this is even recommended by the PHP developers... Has anyone got a quote for me about this? I know thw ZF codinf style includes it as a must. See here : http://framework.zend.com/manual/en/coding-standard.php-file-formatting.html#coding-standard.php-file-formatting.general The Drupal coding standards say to exclude the closing ? on files for the same reason: It avoids a host of problems with whitespace handling and is just one less thing to have to deal with. http://drupal.org/coding-standards --Larry Garfield -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Boolean Assignment Operator
Wow, thanks for the quick replies! I hadn't realised that was purely a bitwise operator. In the strongly-typed Java world, works as a non-lazy (exhaustive?) boolean operator so it has to return a boolean for boolean inputs. Thats the difference here, and Robert got it in one. Gavin. PS. A code restructure isn't really appropriate here. The original executes several SQL statements inside a transaction and needs to know whether to commit or rollback at the end. The example was simplified to get the point across but thanks for the suggestions. On Tue, Feb 3, 2009 at 12:26 AM, Edmund Hertle edmund.her...@student.kit.edu wrote: 2009/2/2 Robert Cummings rob...@interjinn.com On Tue, 2009-02-03 at 00:07 +1100, Gavin Hodge wrote: In Java / C# / C, $bool = $anotherBool; is shorthand for $bool = $bool $anotherBool; So = forces a reference assignment? No, = forces reference assignment. = works as you have written. Cheers, Rob. Oh yeah... sorry, mixed it up... -eddy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Boolean Assignment Operator
2009/2/2 Robert Cummings rob...@interjinn.com On Tue, 2009-02-03 at 00:07 +1100, Gavin Hodge wrote: In Java / C# / C, $bool = $anotherBool; is shorthand for $bool = $bool $anotherBool; So = forces a reference assignment? No, = forces reference assignment. = works as you have written. Cheers, Rob. Oh yeah... sorry, mixed it up... -eddy
[PHP] Blank page of hell..what to look for
Is there a certain thing that should be suspected and looked at first when getting the php blank page of hell I have errors on and nothing is being output anywhere to lead me in the right direction, I have a VariableReveal script (one of you provide and THANK YOU IT HAS BEEN A LIFESAVER) But it is doing nothing today, yesterday the page worked today I get the blank page with not a clue in sight ARGH... Terion
Re: [PHP] Boolean Assignment Operator
On Mon, 2009-02-02 at 23:49 +1100, Gavin Hodge wrote: Hi, I'm fairly new to PHP, having migrated from the Java / C# world. I wrote some code similar to the following: $success = true; $success = operation1(); $success = operation2(); if ($success === true) { operation3(); // depends on 1 and 2 being successful } This didn't work as expected. After a bit of digging I found: * The = operation isn't mentioned anywhere in the PHP documentation * The = function seems to work as expected, however the following is observed... $success = true; $success = true; print $success == true; // outputs 1 print $sucesss === true; // no output * The 'or' assignment operator |= causes no errors but doesn't work. Can any PHP gurus explain why the = operator works at all, and why === seems to fail afterwards? Operators are listed here: http://www.php.net/manual/en/language.operators.precedence.php The compound assignment bitwise operator isn't documented explicitly but the general idea can be found here: http://www.php.net/manual/en/language.operators.assignment.php The === operator is for mathcing values AND data type. By performing a bitwise you are returning data of type integer. As such comparing against boolean true fails when you use ===. Instead what you should do is the following (both for logic and succinctness): ?php $success = 1; $success = operation1(); $success = operation2(); if( $success ) { operation3(); // depends on 1 and 2 being successful } ? Alternatively you can do the following: ?php if( 1 operation1() operation2() ) { operation3(); // depends on 1 and 2 being successful } ? But really what you probably* want is the following: ?php if( operation1() operation2() ) { operation3(); // depends on 1 and 2 being successful } ? Why is the last one the one you probably want? Because if operation1() fails then operation2() won't be evaluated at all... this is usually what you want, but sometimes running operation2() is required to change some state someplace, in which case you can use: ?php if( operation1() operation2() ) { operation3(); // depends on 1 and 2 being successful } ? Of course bitwise only works if they return the same bitfields. For instance if operation1() returns 1, and operation2() returns 2, then the bitwise anding of the values would be false since different bit positions are being combined. 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] Boolean Assignment Operator
2009/2/2 Gavin Hodge gavin.ho...@gmail.com Hi, I'm fairly new to PHP, having migrated from the Java / C# world. I wrote some code similar to the following: $success = true; $success = operation1(); $success = operation2(); if ($success === true) { operation3(); // depends on 1 and 2 being successful } This didn't work as expected. After a bit of digging I found: * The = operation isn't mentioned anywhere in the PHP documentation * The = function seems to work as expected, however the following is observed... $success = true; $success = true; print $success == true; // outputs 1 print $sucesss === true; // no output * The 'or' assignment operator |= causes no errors but doesn't work. Can any PHP gurus explain why the = operator works at all, and why === seems to fail afterwards? Cheers, Gavin. Hey, never heard of the |= operator. So I think php does not support it. I cannot say how = works in Java or C# but as of php it works like that (IMO) (reference instead of copy): $var1 = test1; $var2 = $var1; $var3 = $var1; $var1 = test2; echo var1; // test2 echo var2; // test1 echo var3; // test2
Re: [PHP] Boolean Assignment Operator
On Tue, 2009-02-03 at 00:07 +1100, Gavin Hodge wrote: In Java / C# / C, $bool = $anotherBool; is shorthand for $bool = $bool $anotherBool; So = forces a reference assignment? No, = forces reference assignment. = works as you have written. 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] Re: Payment question in Canada
2009/2/1 Michelle Konzack linux4miche...@tamay-dogan.net Am 2009-01-30 22:47:10, schrieb Edmund Hertle: Read this discussion. I think this will help you: http://marc.info/?t=12329898971r=1w=2 Address Not Found www.marc.info could not be found. Please check the name and try again. Works fine for me. Seems to be a temporarily issue.
[PHP] Boolean Assignment Operator
Hi, I'm fairly new to PHP, having migrated from the Java / C# world. I wrote some code similar to the following: $success = true; $success = operation1(); $success = operation2(); if ($success === true) { operation3(); // depends on 1 and 2 being successful } This didn't work as expected. After a bit of digging I found: * The = operation isn't mentioned anywhere in the PHP documentation * The = function seems to work as expected, however the following is observed... $success = true; $success = true; print $success == true; // outputs 1 print $sucesss === true; // no output * The 'or' assignment operator |= causes no errors but doesn't work. Can any PHP gurus explain why the = operator works at all, and why === seems to fail afterwards? Cheers, Gavin. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Boolean Assignment Operator
In Java / C# / C, $bool = $anotherBool; is shorthand for $bool = $bool $anotherBool; So = forces a reference assignment? On Tue, Feb 3, 2009 at 12:03 AM, Edmund Hertle edmund.her...@student.kit.edu wrote: 2009/2/2 Gavin Hodge gavin.ho...@gmail.com Hi, I'm fairly new to PHP, having migrated from the Java / C# world. I wrote some code similar to the following: $success = true; $success = operation1(); $success = operation2(); if ($success === true) { operation3(); // depends on 1 and 2 being successful } This didn't work as expected. After a bit of digging I found: * The = operation isn't mentioned anywhere in the PHP documentation * The = function seems to work as expected, however the following is observed... $success = true; $success = true; print $success == true; // outputs 1 print $sucesss === true; // no output * The 'or' assignment operator |= causes no errors but doesn't work. Can any PHP gurus explain why the = operator works at all, and why === seems to fail afterwards? Cheers, Gavin. Hey, never heard of the |= operator. So I think php does not support it. I cannot say how = works in Java or C# but as of php it works like that (IMO) (reference instead of copy): $var1 = test1; $var2 = $var1; $var3 = $var1; $var1 = test2; echo var1; // test2 echo var2; // test1 echo var3; // test2 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Another matching question
How do I tell if words_from_the_well is not the value of $page (whether it is the entire value of $page OR within the value of $page) So far I have come up with the following, but it doesn't deal with when $page is only within the value of $page if ( $page words_from_the_well ) { Ron
Re: [PHP] Another matching question
On Mon, 2009-02-02 at 20:35 -0500, Ron Piggott wrote: How do I tell if words_from_the_well is not the value of $page (whether it is the entire value of $page OR within the value of $page) So far I have come up with the following, but it doesn't deal with when $page is only within the value of $page if ( $page words_from_the_well ) { Ron The comparison operator won't work in PHP. What you want maybe is something like this: if(!strstr($page, words_from_the_well)) {} Ash www.ashleysheridan.co.uk
[PHP] How can I do the opposite of property_exists(), maybe a creat_property() in PHP5?
Is there a way to create a new property via PHP 5.2.4? I get a hash back from an authentication server. I'm not guaranteed that someone in another department won't add new key/values to the returned hash/array. I'm trying to work around that part gracefully so that the code doesn't blow up on a customer in such an event. The main try/catch will suppress errors already, but I thought it would be nice to be able to handle this stuff automatically rather than constantly updating a User.class.php file all the time. creating new property this-oraclecustomerid with 1122 but when I try to set the value with the $this-$pkey = $value; It triggers __call() which then triggers __set() which throws my BadProperty exception. How come $this-$pkey = $value isn't creating/setting a property? Or how do I do something like create_property($this, $pkey); so that I can then set it via $this-oraclecustomerid = 1122 or $this-set_oraclecustomerid(1122) ??? ?php function load_from_user_data($user_data) { //now loop through the rest of the user_data array and assign via a set_foo() method foreach ($user_data as $key = $value) { //try { $pkey = strtolower($key); //[dv] this is sort of a hack to automatically create a new property/variable // for 'new' hashes key/values we may not know about. // It's really designed to supress errors and they really should be added to this User.class.php properly. if ( !property_exists($this, $pkey) ) { echo creating new property this-$pkey with $valuebr\n; $this-$pkey = $value; //THIS BLOWS UP ON THE __set() echo this-$pkey = .$this-$pkey; } else { $class_variable = 'set_'.$pkey; $this-$class_variable($value); unset($user_data[$key]); } } //catch (Exception $e) { //echo $e-getMessage().\n; } } //should new fields be returned in the $user_data that are not accounted for above... if ($_SESSION['DEVELOPMENT'] count($user_data)) { echo !-- Unaccounted for user_data hashes. Please add these into User.class.php:\n; var_dump($user_data); echo --; } //THESE TWO LINES FATAL ERROR ON THE __get(): echo this-oraclecustomerid = .$this-oraclecustomerid; echo this-get_oraclecustomerid() = .$this-get_oraclecustomerid(); } ?
Re: [PHP] PHP Linux/Windows Outlook 2003 HTML email problem
It seems like this solves the issue: http://pear.php.net/bugs/bug.php?id=12032 Sorry, just hadn't found this before. Tim-Hinnerk Heuer http://www.ihostnz.com On Mon, Feb 2, 2009 at 7:24 PM, Chris dmag...@gmail.com wrote: German Geek wrote: Hi All, We've got a problem with our Ubuntu Linux machine sending HTML emails to Outlook 2003: It's an Ubuntu Server (uname -a Linux CDR2-221 2.6.24-19-server #1 SMP Wed Jun 18 15:18:00 UTC 2008 i686 GNU/Linux) with the newest version of Postfix installed as the Mail server. Unfortunately, all emails sent as HTML, using the PEAR library for sending email like so: Best place to look at this would be the pear list: http://pear.php.net/support/lists.php -- Postgresql php tutorials http://www.designmagick.com/
[PHP] Visibility of class constant
I got a weird behaviour of class constant. Suppose I have Index_Controller and Another_Controller classes, both extending Controller class. I define some constants (let's assume I only have one, call it MY_CONST) in Controller class to be used by its descendants. In Index_Controller, I can freely use MY_CONST without parent:: needed. However, this isn't the case with Another_Controller. Without parent:: I got notice Use of undefined constant MY_CONST - assumed 'MY_CONST'. How could this happen and what's the correct behaviour? It's actually nicer to have it without parent::, assuming that constants have protected visibility specifier (which isn't possible AFAIK :-( ). -- View this message in context: http://www.nabble.com/Visibility-of-class-constant-tp21803985p21803985.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Throwing an exception seems to defeat output buffering
I would expect that if I turn on output buffering, echo something, throw an exception, and catch the exception, nothing will have been actually output. That doesn't seem to be the case. Throwing an exception seems to defeat output buffering. In the following code, I would not expect to see the h1, but I do. ? try { ob_start(); echo 'h1You should not see this!/h1'; throw new Exception('h2This should be the first output./h2'); exit( 'Contents: ' . ob_get_clean()); } catch (Exception $ex) { exit('h2Exception:/h2' . $ex-getMessage()); } I'm exercising that code on PHP 5.2.4 and 5.2.8. Does anybody know why throwing an exception seems to override ob_start(), flushing the buffered output? Is there a workaround? Thank you, Leif Wickland -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How can I do the opposite of property_exists(), maybe a creat_property() in PHP5?
2009/2/3 Daevid Vincent dae...@daevid.com Is there a way to create a new property via PHP 5.2.4? I get a hash back from an authentication server. I'm not guaranteed that someone in another department won't add new key/values to the returned hash/array. I'm trying to work around that part gracefully so that the code doesn't blow up on a customer in such an event. The main try/catch will suppress errors already, but I thought it would be nice to be able to handle this stuff automatically rather than constantly updating a User.class.php file all the time. creating new property this-oraclecustomerid with 1122 but when I try to set the value with the $this-$pkey = $value; It triggers __call() which then triggers __set() which throws my BadProperty exception. How come $this-$pkey = $value isn't creating/setting a property? Or how do I do something like create_property($this, $pkey); so that I can then set it via $this-oraclecustomerid = 1122 or $this-set_oraclecustomerid(1122) ??? ?php function load_from_user_data($user_data) { //now loop through the rest of the user_data array and assign via a set_foo() method foreach ($user_data as $key = $value) { //try { $pkey = strtolower($key); //[dv] this is sort of a hack to automatically create a new property/variable // for 'new' hashes key/values we may not know about. // It's really designed to supress errors and they really should be added to this User.class.php properly. if ( !property_exists($this, $pkey) ) { echo creating new property this-$pkey with $valuebr\n; $this-$pkey = $value; //THIS BLOWS UP ON THE __set() echo this-$pkey = .$this-$pkey; } Hey, well, $this-$pkey is wrong syntax. Try $this-pkey = $value -eddy else { $class_variable = 'set_'.$pkey; $this-$class_variable($value); unset($user_data[$key]); } } //catch (Exception $e) { //echo $e-getMessage().\n; } } //should new fields be returned in the $user_data that are not accounted for above... if ($_SESSION['DEVELOPMENT'] count($user_data)) { echo !-- Unaccounted for user_data hashes. Please add these into User.class.php:\n; var_dump($user_data); echo --; } //THESE TWO LINES FATAL ERROR ON THE __get(): echo this-oraclecustomerid = .$this-oraclecustomerid; echo this-get_oraclecustomerid() = .$this-get_oraclecustomerid(); } ?