php-general Digest 2 Feb 2009 15:22:12 -0000 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


----------------------------------------------------------------------
--- Begin Message ---
        ~~~~~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 ---
--- Begin Message ---
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) warnings which i thought should be ok:

*Strict Standards*: Assigning the return value of new by reference is
deprecated in */usr/share/php/Mail.php* on line *154*

*Strict Standards*: Assigning the return value of new by reference is
deprecated in */usr/share/php/PEAR.php* on line *569*

*Strict Standards*: Assigning the return value of new by reference is
deprecated in */usr/share/php/PEAR.php* on line *572*

*Strict Standards*: Non-static method Mail::factory() should not be called
statically in */home/magsbyme/www/
ljhooker.ddm.magsbyme.com/lib/myTools.class.php* on line *1035*

*Strict Standards*: Non-static method PEAR::isError() should not be called
statically, assuming $this from incompatible context in *
/usr/share/php/Mail.php* on line *156*

*Strict Standards*: is_a(): Deprecated. Please use the instanceof operator
in */usr/share/php/PEAR.php* on line *281*

*Strict Standards*: Non-static method PEAR::isError() should not be called
statically, assuming $this from incompatible context in *
/usr/share/php/Mail/mail.php* on line *115*

*Strict Standards*: is_a(): Deprecated. Please use the instanceof operator
in */usr/share/php/PEAR.php* on line *281*

*Strict Standards*: Non-static method Mail::factory() should not be called
statically in */home/magsbyme/www/
ljhooker.ddm.magsbyme.com/lib/myTools.class.php* on line *1035*

*Strict Standards*: Non-static method PEAR::isError() should not be called
statically, assuming $this from incompatible context in *
/usr/share/php/Mail.php* on line *156*

*Strict Standards*: is_a(): Deprecated. Please use the instanceof operator
in */usr/share/php/PEAR.php* on line *281*

*Strict Standards*: Non-static method PEAR::isError() should not be called
statically, assuming $this from incompatible context in *
/usr/share/php/Mail/mail.php* on line *115*

*Strict Standards*: is_a(): Deprecated. Please use the instanceof operator
in */usr/share/php/PEAR.php* on line *281*

*Strict Standards*: Non-static method Mail::factory() should not be called
statically in */home/magsbyme/www/
ljhooker.ddm.magsbyme.com/lib/myTools.class.php* on line *1035*

*Strict Standards*: Non-static method PEAR::isError() should not be called
statically, assuming $this from incompatible context in *
/usr/share/php/Mail.php* on line *156*

*Strict Standards*: is_a(): Deprecated. Please use the instanceof operator
in */usr/share/php/PEAR.php* on line *281*

*Strict Standards*: Non-static method PEAR::isError() should not be called
statically, assuming $this from incompatible context in *
/usr/share/php/Mail/mail.php* on line *115*

*Strict Standards*: is_a(): Deprecated. Please use the instanceof operator
in */usr/share/php/PEAR.php* on line *281*

*Strict Standards*: Non-static method PEAR::raiseError() should not be
called statically, assuming $this from incompatible context in *
/usr/share/php/Mail/mail.php* on line *136*

*Strict Standards*: Non-static method PEAR::getStaticProperty() should not
be called statically, assuming $this from incompatible context in *
/usr/share/php/PEAR.php* on line *867*

*Strict Standards*: Non-static method Mail::factory() should not be called
statically in */home/magsbyme/www/
ljhooker.ddm.magsbyme.com/lib/myTools.class.php* on line *1035*

*Strict Standards*: Non-static method PEAR::isError() should not be called
statically, assuming $this from incompatible context in *
/usr/share/php/Mail.php* on line *156*

*Strict Standards*: is_a(): Deprecated. Please use the instanceof operator
in */usr/share/php/PEAR.php* on line *281*

*Strict Standards*: Non-static method PEAR::isError() should not be called
statically, assuming $this from incompatible context in *
/usr/share/php/Mail/mail.php* on line *115*

*Strict Standards*: is_a(): Deprecated. Please use the instanceof operator
in */usr/share/php/PEAR.php* on line *281*

*Strict Standards*: Non-static method Mail::factory() should not be called
statically in */home/magsbyme/www/
ljhooker.ddm.magsbyme.com/lib/myTools.class.php* on line *1035*

*Strict Standards*: Non-static method PEAR::isError() should not be called
statically, assuming $this from incompatible context in *
/usr/share/php/Mail.php* on line *156*

*Strict Standards*: is_a(): Deprecated. Please use the instanceof operator
in */usr/share/php/PEAR.php* on line *281*

*Strict Standards*: Non-static method PEAR::isError() should not be called
statically, assuming $this from incompatible context in *
/usr/share/php/Mail/mail.php* on line *115*

*Strict Standards*: is_a(): Deprecated. Please use the instanceof operator
in */usr/share/php/PEAR.php* on line *281*

*Strict Standards*: Non-static method PEAR::raiseError() should not be
called statically, assuming $this from incompatible context in *
/usr/share/php/Mail/mail.php* on line *136*

*Strict Standards*: Non-static method PEAR::getStaticProperty() should not
be called statically, assuming $this from incompatible context in *
/usr/share/php/PEAR.php* on line *867*

*Warning*: Cannot modify header information - headers already sent by
(output started at /usr/share/php/Mail.php:154) in */home/magsbyme/www/
ljhooker.ddm.magsbyme.com/lib/symfony/exception/sfException.class.php* on
line *101

*Hope this information is enough for someone to know what's going on. Help
is much appreciated.
Thanks,
Tim

Tim-Hinnerk Heuer

http://www.ihostnz.com

--- End Message ---
--- Begin Message ---
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/


--- End Message ---
--- Begin Message ---
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
>
> --
> Alpar Torok
>

Ah, that must have been it. Thank you.
So, again, I can only recommend you to ommit them because it really
protects you from some stupid bugs that can cost you hours to find.

-- 
Currently developing a browsergame...
http://www.p-game.de
Trade - Expand - Fight

Follow me at twitter!
http://twitter.com/moortier

--- End Message ---
--- Begin Message ---
Hi,

My php script is located on server with https protocol:
https://www.somesite.com/myscript.php

How can i check public key of client certificate, used for connection from client to server? I need to do it in php script.

--
Serge

--- End Message ---
--- Begin Message ---
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=123298989700001&r=1&w=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.

--- End Message ---
--- Begin Message ---
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

--- End Message ---
--- Begin Message ---
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)

--- End Message ---
--- Begin Message ---
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

--- End Message ---
--- Begin Message ---
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

--- End Message ---
--- Begin Message ---
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.

--- End Message ---
--- Begin Message ---
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"

--- End Message ---
--- Begin Message ---
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"
>
>

--- End Message ---
--- Begin Message ---
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


--- End Message ---
--- Begin Message ---
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


--- End Message ---
--- Begin Message ---
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

--- End Message ---
--- Begin Message ---
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

--- End Message ---
--- Begin Message ---
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
>

--- End Message ---
--- Begin Message ---

> -----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-gene...@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;



--- End Message ---
--- Begin Message ---
"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 



--- End Message ---
--- Begin Message --- 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...




--- End Message ---

Reply via email to