php-general Digest 21 Nov 2007 00:29:50 -0000 Issue 5139

Topics (messages 264859 through 264886):

Re: overloading members. aghhh!!!
        264859 by: Peter Ford
        264874 by: Jochem Maas

Re: two small issues with php mail
        264860 by: Wolf
        264861 by: Jim Lucas
        264862 by: Jim Lucas
        264863 by: Wolf
        264864 by: Stut
        264865 by: Philip Thompson
        264866 by: Andrés Robinet
        264867 by: Børge Holen
        264868 by: Stut
        264869 by: Børge Holen
        264870 by: Per Jessen
        264871 by: Michael McGlothlin
        264873 by: Jason Pruim
        264876 by: Steve Edberg
        264877 by: Stephen Johnson

manipulating XML via php DOM
        264872 by: pere roca

__sleep() strange behavior with file writting and SESSION using
        264875 by: Julien Pauli
        264880 by: Julien Pauli
        264881 by: chetan rane
        264882 by: Andrés Robinet
        264883 by: Andrés Robinet
        264885 by: Jochem Maas

Re: two small issues with php mail OT
        264878 by: Jay Blanchard
        264879 by: Stephen Johnson
        264884 by: Jochem Maas
        264886 by: Børge Holen

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
Jochem Maas wrote:
> Kiketom wrote:
>> Hi all.
>> Yesterday i have looking for the overloading members
>>
>> Member overloading
>> void __set ( string name, mixed value )
>> mixed __get ( string name )
>>
>> As an example i put this code:
>>
>> class foo
>> {
>>     private $ID;
>>     private $Name;
>>     private $LastName;
> 
> when you declare these three as 'real' members, __get() and __set()
> will no longer be called - they are only called for non-existent members.
> 
Nope, that's not true. If the members are private, or otherwise inaccessible,
__get() and __set() are called - I've used this in a few places to provide a
"read-only" member variable, e.g.:

class foo
{
        private $bar=0;

        public function __get($nm)
        {
                return $this->$nm;
        }

        public function __set($nm,$val)
        {
                if ($nm != 'bar')
                {
                        $this->$nm = $val;
                }
        }
}

--- End Message ---
--- Begin Message ---
Peter Ford wrote:
> Jochem Maas wrote:
>> Kiketom wrote:
>>> Hi all.
>>> Yesterday i have looking for the overloading members
>>>
>>> Member overloading
>>> void __set ( string name, mixed value )
>>> mixed __get ( string name )
>>>
>>> As an example i put this code:
>>>
>>> class foo
>>> {
>>>     private $ID;
>>>     private $Name;
>>>     private $LastName;
>> when you declare these three as 'real' members, __get() and __set()
>> will no longer be called - they are only called for non-existent members.
>>
> Nope, that's not true. 

Indeed. I did post back to say I was talking ****.

If the members are private, or otherwise inaccessible,

I believe that this was not always the case (i.e. that in
older versions private members behaved the same way as public
members with regard to __get()/__set() - I'm not sure but I think so)

> __get() and __set() are called - I've used this in a few places to provide a
> "read-only" member variable, e.g.:
> 
> class foo
> {
>       private $bar=0;
> 
>       public function __get($nm)
>       {
>               return $this->$nm;
>       }
> 
>       public function __set($nm,$val)
>       {
>               if ($nm != 'bar')
>               {
>                       $this->$nm = $val;
>               }
>       }
> }
> 

--- End Message ---
--- Begin Message ---
---- Jim Lucas <[EMAIL PROTECTED]> wrote: 
> Per Jessen wrote:
> > Brad wrote:
<!-- Snip for brevity -->
> 
> remember, he is wanting to setup SMTP auth.  So he will not be using 
> PHP's mail() function.
> 
> He needs to talk directly to the SMTP server.
> 
> Jim
 Jim,

At this point, we need to just get his homework assignment parameters from 
"Brad" so we can see what next questions he'll have...  I'm not sure he needs 
to do SMTP auth but even if he does, he's going to need to be able to write 
correct syntax and debug his code along the way...

Wolf

--- End Message ---
--- Begin Message ---
Stut wrote:
Brad wrote:
<?

$email = $_REQUEST['email'];

$fromaddress = '[EMAIL PROTECTED]';

$fromname = 'Zone of success Club'; $eol = "\r\n";

$headers  = 'From: '.$fromname.' <'.$fromaddress.'>'.$eol;

// $headers = 'bcc: '[EMAIL PROTECTED]';

$headers .= 'Reply-To: '.$fromname.' <'.$fromaddress.'>'.$eol;

$headers .= 'Return-Path: '.$fromname.' <'.$fromaddress.'>'.$eol;

$headers .= 'X-Mailer: PHP '.phpversion().$eol;

$headers .= 'Content-Type: text/html; charset=iso-8859-1'.$eol;

$headers .= 'Content-Transfer-Encoding: 8bit';

$subject = 'Your free book!';

$body = '<a
href="http://www.zoneofsuccessclub.com/freePDF/autopilotebook.pdf";>"Click
ME"</a>  Here is your FREE autopilot book!!!!';

mail($email, $subject, $body, $headers);

?>

Take this, be grateful and feel free to try Ruby. Email addresses have been changed to protect your victims.

<?php
  // You REALLY REALLY need to be doing some validation on this variable
  $email = $_REQUEST['email'];
  // This is the address the email will appear to come from
  $fromaddress = '[EMAIL PROTECTED]';
  // And this is the name
  $fromname = 'Zone of success Club';
  // This is the header separator, it *does* need the \r
  $eol = "\r\n";
  // Now we start building the headers, starting with from
  $headers  = 'From: '.$fromname.' <'.$fromaddress.'>'.$eol;
  // Then we *concatenate* the next header to $headers
  $headers .= 'bcc: <[EMAIL PROTECTED]>'.$eol;
  // Some more headers, some pointless but I can't be arsed to argue
  $headers .= 'Reply-To: '.$fromname.' <'.$fromaddress.'>'.$eol;
  // Removed the name on this one - it's not supposed to have one
  $headers .= 'Return-Path: <'.$fromaddress.'>'.$eol;
  $headers .= 'X-Mailer: PHP '.phpversion().$eol;
  $headers .= 'Content-Type: text/html; charset=iso-8859-1'.$eol;
  $headers .= 'Content-Transfer-Encoding: 8bit';
  $subject = 'Your free book!';
$body = '<a href="http://www.zoneofsuccessclub.com/freePDF/autopilotebook.pdf";>"Click
ME"</a>  Here is your FREE autopilot book!!!!';
  mail($email, $subject, $body, $headers);
?>

I've tested this on a pretty standard install of PHP 5.1.1, and it works, bcc and all.

-Stut


You forgot the second part of the project, SMTP auth. Can't do it this way. Have to use fsockopen() or something to talk directly to the SMTP server.


--
Jim Lucas


    "Perseverance is not a long race;
        it is many short races one after the other"

Walter Elliot



    "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

--- End Message ---
--- Begin Message ---
Wolf wrote:
---- Jim Lucas <[EMAIL PROTECTED]> wrote:
Per Jessen wrote:
Brad wrote:
<!-- Snip for brevity -->
remember, he is wanting to setup SMTP auth. So he will not be using PHP's mail() function.

He needs to talk directly to the SMTP server.

Jim
 Jim,

At this point, we need to just get his homework assignment parameters from 
"Brad" so we can see what next questions he'll have...  I'm not sure he needs 
to do SMTP auth but even if he does, he's going to need to be able to write correct 
syntax and debug his code along the way...

Wolf

Well, re-reading his first post, it does seem like the only two things he is interested in solving, besides syntax and formatting, are SMTP auth and using the BCC to send to additional addresses.

--
Jim Lucas


    "Perseverance is not a long race;
        it is many short races one after the other"

Walter Elliot



    "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

--- End Message ---
--- Begin Message ---
---- Jim Lucas <[EMAIL PROTECTED]> wrote: 
> Wolf wrote:
> > ---- Jim Lucas <[EMAIL PROTECTED]> wrote: 
> >> Per Jessen wrote:
> >>> Brad wrote:
> > <!-- Snip for brevity -->
> >> remember, he is wanting to setup SMTP auth.  So he will not be using 
> >> PHP's mail() function.
> >>
> >> He needs to talk directly to the SMTP server.
> >>
> >> Jim
> >  Jim,
> > 
> > At this point, we need to just get his homework assignment parameters from 
> > "Brad" so we can see what next questions he'll have...  I'm not sure he 
> > needs to do SMTP auth but even if he does, he's going to need to be able to 
> > write correct syntax and debug his code along the way...
> > 
> > Wolf
> 
> Well, re-reading his first post, it does seem like the only two things 
> he is interested in solving, besides syntax and formatting, are SMTP 
> auth and using the BCC to send to additional addresses.
> 
> -- 
> Jim Lucas
> 

Actually, reading his "first post" tells you that he is trying to get this to 
work "for his business" and he's too much "into this guy for $$$" to go with a 
MySQL databased mailing list setup to get his email sent...

Wolf

--- End Message ---
--- Begin Message ---
Jim Lucas wrote:
Stut wrote:
Brad wrote:
<?

$email = $_REQUEST['email'];

$fromaddress = '[EMAIL PROTECTED]';

$fromname = 'Zone of success Club'; $eol = "\r\n";

$headers  = 'From: '.$fromname.' <'.$fromaddress.'>'.$eol;

// $headers = 'bcc: '[EMAIL PROTECTED]';

$headers .= 'Reply-To: '.$fromname.' <'.$fromaddress.'>'.$eol;

$headers .= 'Return-Path: '.$fromname.' <'.$fromaddress.'>'.$eol;

$headers .= 'X-Mailer: PHP '.phpversion().$eol;

$headers .= 'Content-Type: text/html; charset=iso-8859-1'.$eol;

$headers .= 'Content-Transfer-Encoding: 8bit';

$subject = 'Your free book!';

$body = '<a
href="http://www.zoneofsuccessclub.com/freePDF/autopilotebook.pdf";>"Click
ME"</a>  Here is your FREE autopilot book!!!!';

mail($email, $subject, $body, $headers);

?>

Take this, be grateful and feel free to try Ruby. Email addresses have been changed to protect your victims.

<?php
  // You REALLY REALLY need to be doing some validation on this variable
  $email = $_REQUEST['email'];
  // This is the address the email will appear to come from
  $fromaddress = '[EMAIL PROTECTED]';
  // And this is the name
  $fromname = 'Zone of success Club';
  // This is the header separator, it *does* need the \r
  $eol = "\r\n";
  // Now we start building the headers, starting with from
  $headers  = 'From: '.$fromname.' <'.$fromaddress.'>'.$eol;
  // Then we *concatenate* the next header to $headers
  $headers .= 'bcc: <[EMAIL PROTECTED]>'.$eol;
  // Some more headers, some pointless but I can't be arsed to argue
  $headers .= 'Reply-To: '.$fromname.' <'.$fromaddress.'>'.$eol;
  // Removed the name on this one - it's not supposed to have one
  $headers .= 'Return-Path: <'.$fromaddress.'>'.$eol;
  $headers .= 'X-Mailer: PHP '.phpversion().$eol;
  $headers .= 'Content-Type: text/html; charset=iso-8859-1'.$eol;
  $headers .= 'Content-Transfer-Encoding: 8bit';
  $subject = 'Your free book!';
$body = '<a href="http://www.zoneofsuccessclub.com/freePDF/autopilotebook.pdf";>"Click
ME"</a>  Here is your FREE autopilot book!!!!';
  mail($email, $subject, $body, $headers);
?>

I've tested this on a pretty standard install of PHP 5.1.1, and it works, bcc and all.

-Stut


You forgot the second part of the project, SMTP auth. Can't do it this way. Have to use fsockopen() or something to talk directly to the SMTP server.

Point me to the message where Brad mentions SMTP auth. I can't find it. Looking back at the thread you were the first person to mention SMTP auth. Brad talked about SMTP (clearly not understanding what it is) - you added the auth.

Let's not go over-complicating the issue, the guy is already having some serious problems.

-Stut

--
http://stut.net/

--- End Message ---
--- Begin Message ---
On Nov 20, 2007 9:13 AM, Wolf <[EMAIL PROTECTED]> wrote:

> ---- Jim Lucas <[EMAIL PROTECTED]> wrote:
> > Wolf wrote:
> > > ---- Jim Lucas <[EMAIL PROTECTED]> wrote:
> > >> Per Jessen wrote:
> > >>> Brad wrote:
> > > <!-- Snip for brevity -->
> > >> remember, he is wanting to setup SMTP auth.  So he will not be using
> > >> PHP's mail() function.
> > >>
> > >> He needs to talk directly to the SMTP server.
> > >>
> > >> Jim
> > >  Jim,
> > >
> > > At this point, we need to just get his homework assignment parameters
> from "Brad" so we can see what next questions he'll have...  I'm not sure he
> needs to do SMTP auth but even if he does, he's going to need to be able to
> write correct syntax and debug his code along the way...
> > >
> > > Wolf
> >
> > Well, re-reading his first post, it does seem like the only two things
> > he is interested in solving, besides syntax and formatting, are SMTP
> > auth and using the BCC to send to additional addresses.
> >
> > --
> > Jim Lucas
> >
>
> Actually, reading his "first post" tells you that he is trying to get this
> to work "for his business" and he's too much "into this guy for $$$" to go
> with a MySQL databased mailing list setup to get his email sent...
>
> Wolf



Is there a community agreement that this guy (Brad) should be blacklisted?
=P

~Philip

--- End Message ---
--- Begin Message ---
> Wolf wrote:
> > ---- Jim Lucas <[EMAIL PROTECTED]> wrote:
> >> Per Jessen wrote:
> >>> Brad wrote:
> > <!-- Snip for brevity -->
> >> remember, he is wanting to setup SMTP auth.  So he will not be using
> >> PHP's mail() function.
> >>
> >> He needs to talk directly to the SMTP server.
> >>
> >> Jim
> >  Jim,
> >
> > At this point, we need to just get his homework assignment parameters
> from "Brad" so we can see what next questions he'll have...  I'm not
> sure he needs to do SMTP auth but even if he does, he's going to need
> to be able to write correct syntax and debug his code along the way...
> >
> > Wolf
> 
> Well, re-reading his first post, it does seem like the only two things
> he is interested in solving, besides syntax and formatting, are SMTP
> auth and using the BCC to send to additional addresses.
> 
> --
> Jim Lucas
> 
> 
>      "Perseverance is not a long race;
>          it is many short races one after the other"
> 
> Walter Elliot
> 
> 
> 
>      "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
> 
> --

Well, I didn't read Brad's first post (I subscribed to this list recently); but 
what I know for sure is that "PHP: Talking to a SMTP server" cannot be the 
title for an assignment in a first course on PHP (judging for Brad's inquiries, 
this is it).
Nobody (me included) likes doing assignments for anybody, and that's not what 
this list is for either... but I've not seen any of you throwing a link for a 
video tutorial.
When I started learning PHP it was kind of a new world, though I had some 
experience in C, C++, C#, VB, Delphi, Actionscript and Javascript. So I RTFM 
for the syntactic elements to compare and see the differences with other 
languages I knew, and then I jumped over a set of tutorials for the basic 
functionality like using $_GET, $_POST, $_SESSION, sending out emails and 
accessing databases (for Spanish speakers like me we have 
http://www.illasaron.com with tones of GB in FREE training videos, for English 
speakers I don't know). Only when I felt a bit comfortable I started coding my 
stuff... and I didn't bother anybody in any forum or mail list.
I bet my life that the only one goal of Brad's assignment is "How to populate 
the headers parameter for the mail function" and the rest of it... is the 
result of Brad's googling and not knowing what to ask. I believe 120% he wants 
SMTP Auth only because his code is failing and he thinks that will fix the 
issue.
Anyway... all that said, I only hope that once he gets it straight he says 
"Thanks guys, this was the issue and this is how it got solved"

Rob

--- End Message ---
--- Begin Message ---
OMG the top posting on this freakin' issue is a headache

-- 
---
Børge Holen
http://www.arivene.net

--- End Message ---
--- Begin Message ---
Børge Holen wrote:
OMG the top posting on this freakin' issue is a headache

Whereas removing all of the previous message is like a sensual massage.

-Stut

--
http://stut.net/

--- End Message ---
--- Begin Message ---
On Tuesday 20 November 2007 17:49:02 Stut wrote:
> Børge Holen wrote:
> > OMG the top posting on this freakin' issue is a headache
>
> Whereas removing all of the previous message is like a sensual massage.

okey...

>
> -Stut
>
> --
> http://stut.net/



-- 
---
Børge Holen
http://www.arivene.net

--- End Message ---
--- Begin Message ---
Stut wrote:

> Børge Holen wrote:
>> OMG the top posting on this freakin' issue is a headache
> 
> Whereas removing all of the previous message is like a sensual
> massage.
> 

Pure stress-relief. 


/Per Jessen, Zürich

--- End Message ---
--- Begin Message ---
I hate top posters. Pure evil.
OMG the top posting on this freakin' issue is a headache
Whereas removing all of the previous message is like a sensual
massage
Pure stress-relief.

--- End Message ---
--- Begin Message ---
Honestly for me... top posting,
On Nov 20, 2007, at 1:19 PM, Michael McGlothlin wrote:

I hate top posters. Pure evil.
OMG the top posting on this freakin' issue is a headache

Whereas removing all of the previous message is like a sensual
massage

inline posting,


Pure stress-relief.

bottom posting...

None of it matters... As long as it's CONSISTENT through out the thread :) It's all just as easy for me to follow. Now... Trimming on the other hand annoys me... if you trim to much then you have to go back and look up the e-mail that the info was in :)

*Gets ready to duck* :)






--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424
www.raoset.com
[EMAIL PROTECTED]

--- End Message ---
--- Begin Message ---
Personally      At 1:31 PM -0500 11/20/07, Jason Pruim wrote:
I prefer        >Honestly for me... top posting,
side            >On Nov 20, 2007, at 1:19 PM, Michael McGlothlin wrote:
posting.        >>
                >>I hate top posters. Pure evil.
-steve          >>>>OMG the top posting on this freakin' issue is a headache
                >>>>
>>>Whereas removing all of the previous message is like a sensual
                >>>massage
                >
                >inline posting,
                >
                >>>


                PS. Sometimes interlacing is


                >>>Pure stress-relief.


appropriate as well.


                >
                >bottom posting...
                >
>None of it matters... As long as it's CONSISTENT through out the thread :) >It's all just as easy for me to follow. Now... Trimming on the other hand >annoys me... if you trim to much then you have to go back and look up the >e-mail that the info was in :)
                >
                >*Gets ready to duck* :)

--
+--------------- my people are the people of the dessert, ---------------+
| Steve Edberg                                http://pgfsun.ucdavis.edu/ |
| UC Davis Genome Center                            [EMAIL PROTECTED] |
| Bioinformatics programming/database/sysadmin             (530)754-9127 |
+---------------- said t e lawrence, picking up his fork ----------------+

--- End Message ---
--- Begin Message ---
I wrote about this a long time ago ... In a galaxy far far away...

http://www.thelonecoder.com/Blog/?p=7

Be good lemmings and do as you're told...
--
Stephen Johnson c | eh
The Lone Coder

http://www.thelonecoder.com
continuing the struggle against bad code

http://www.thumbnailresume.com
--




> From: Michael McGlothlin <[EMAIL PROTECTED]>
> Date: Tue, 20 Nov 2007 11:19:22 -0700
> To: Per Jessen <[EMAIL PROTECTED]>
> Cc: <[EMAIL PROTECTED]>
> Subject: Re: [PHP] two small issues with php mail
> 
> I hate top posters. Pure evil.
>>>> OMG the top posting on this freakin' issue is a headache
>>>>       
>>> Whereas removing all of the previous message is like a sensual
>>> massage
>> Pure stress-relief.
>>   
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

--- End Message ---
--- Begin Message ---
please, I need some help with php DOM, for me it's becoming a hell!

After trying other methods (check message from 19th november, called "php
DOM question"), I'm getting a little more success to manipulate XML.

>From the code you can see below you generate this xml. Now I just want to
keep only the initial <Or> and the final </Or>. How can I access and delete
the other (the "between" tags)? 
I suppose there is no way to create an initial <Or> without the associated
</Or>.
Thanks a lot,

Pere
 
This is the WRONG XML generated from code. 
...
<And>

  <PropertyIsEqualTo>
    <PropertyName>genus</PropertyName>
    <Literal>ontophaugs332</Literal>
  </PropertyIsEqualTo>

<Or>

   <PropertyIsEqualTo>
     <PropertyName>genus</PropertyName>
        <Literal>copris</Literal>
   </PropertyIsEqualTo>
</Or>
<Or>

   <PropertyIsEqualTo>
     <PropertyName>genus</PropertyName>
        <Literal>copris2</Literal>
   </PropertyIsEqualTo>
</Or>
</And>

<?php
$species=array('ontophaugs332','copris','copris2');
$dom = new DOMDocument;
//XML we will insert the data to
$dom -> load('edit_iberia3.xml');


$count=count($species);

foreach ($species as $sp=>$value) {
//we pass parameters of the array

        $where_to_insert= $dom->getElementsByTagName('And')->item(0);
    
        $child = $dom->createElement('Or');             
        $or=$where_to_insert->appendChild($child);
        
        $child = $dom->createElement('PropertyIsEqualTo');              
        $first=$or->appendChild($child);
  
        $child2 = $dom->createElement('PropertyName');
        $first->appendChild($child2);
        
        $child3 = $dom->createElement('Literal');
        $first->appendChild($child3);

        //inserting the array data
        $values = $dom->createTextNode($value);
        $values = $child3->appendChild($values);
     }

echo $dom->save(nou_iberia);
?> 
-- 
View this message in context: 
http://www.nabble.com/manipulating-XML-via-php-DOM-tf4845510.html#a13862945
Sent from the PHP - General mailing list archive at Nabble.com.

--- End Message ---
--- Begin Message ---
Consider that very simple code, that runs on PHP 5.2.5 onto a Windows
machine :
<?php
class a
{
    public $b;

    public function __sleep()
    {
        file_put_contents("log.txt","ok" . PHP_EOL,FILE_APPEND);
        echo "done!";
        return array();
    }
}

$a = new a;
serialize($a);
?>

No problem here, log.txt is writtable, when it passes on the serialize()
instruction, it goes to __sleep and works well.
"OK\r\n" is appended to the log file , and "done!" is displayed.



Now consider this :

<?php
session_start();
class a
{
    public $b;

    public function __sleep()
    {
        file_put_contents("log.txt","ok" . PHP_EOL,FILE_APPEND);
        echo "done!";
        return array();
    }
}

$a = new a;
$_SESSION['obj'] = $a;
?>

In this case, when the object is going in the session, it naturally passes
throught __sleep().
The problem is that file_put_contents() doesn't work -> the file is not
appended "OK\r\n" as it should be.
"done!" is displayed , and if you look at the return value of
file_put_contents ( number of bytes that have been written ) : it's all
right ! It simply doesn not write to the file.

Anyone has an idea ?
Is this a bug ?
Thx :)

--- End Message ---
--- Begin Message ---
Sorry but it goes throught __sleep() as session serializes objects before
storing them
Proof is that "done!" is echoed.
Step by step debugging also prove that , the only thing is that
file_put_contents, doesn't execute, but returns a value...



2007/11/20, chetan rane <[EMAIL PROTECTED]>:
>
> This aint a bug
>
> because __sleep is called only when you serialize an object and not when
> you assign it to a session Variable;
>
> On Nov 21, 2007 12:21 AM, Julien Pauli < [EMAIL PROTECTED]> wrote:
>
> > Consider that very simple code, that runs on PHP 5.2.5 onto a Windows
> > machine :
> > <?php
> > class a
> > {
> >    public $b;
> >
> >    public function __sleep()
> >    {
> >        file_put_contents("log.txt","ok" . PHP_EOL,FILE_APPEND);
> >        echo "done!";
> >        return array();
> >    }
> > }
> >
> > $a = new a;
> > serialize($a);
> > ?>
> >
> > No problem here, log.txt is writtable, when it passes on the serialize()
> > instruction, it goes to __sleep and works well.
> > "OK\r\n" is appended to the log file , and "done!" is displayed.
> >
> >
> >
> > Now consider this :
> >
> > <?php
> > session_start();
> > class a
> > {
> >    public $b;
> >
> >    public function __sleep()
> >    {
> >        file_put_contents("log.txt","ok" . PHP_EOL,FILE_APPEND);
> >        echo "done!";
> >        return array();
> >    }
> > }
> >
> > $a = new a;
> > $_SESSION['obj'] = $a;
> > ?>
> >
> > In this case, when the object is going in the session, it naturally
> > passes
> > throught __sleep().
> > The problem is that file_put_contents() doesn't work -> the file is not
> > appended "OK\r\n" as it should be.
> > "done!" is displayed , and if you look at the return value of
> > file_put_contents ( number of bytes that have been written ) : it's all
> > right ! It simply doesn not write to the file.
> >
> > Anyone has an idea ?
> > Is this a bug ?
> > Thx :)
> >
>
>
>
> --
> Have A plesant Day
> Chetan. D. Rane
> Location: India
> Contact: +91-9844922489
> otherID: [EMAIL PROTECTED]
>             [EMAIL PROTECTED]
>

--- End Message ---
--- Begin Message ---
This aint a bug

because __sleep is called only when you serialize an object and not when you
assign it to a session Variable;

On Nov 21, 2007 12:21 AM, Julien Pauli <[EMAIL PROTECTED]> wrote:

> Consider that very simple code, that runs on PHP 5.2.5 onto a Windows
> machine :
> <?php
> class a
> {
>    public $b;
>
>    public function __sleep()
>    {
>        file_put_contents("log.txt","ok" . PHP_EOL,FILE_APPEND);
>        echo "done!";
>        return array();
>    }
> }
>
> $a = new a;
> serialize($a);
> ?>
>
> No problem here, log.txt is writtable, when it passes on the serialize()
> instruction, it goes to __sleep and works well.
> "OK\r\n" is appended to the log file , and "done!" is displayed.
>
>
>
> Now consider this :
>
> <?php
> session_start();
> class a
> {
>    public $b;
>
>    public function __sleep()
>    {
>        file_put_contents("log.txt","ok" . PHP_EOL,FILE_APPEND);
>        echo "done!";
>        return array();
>    }
> }
>
> $a = new a;
> $_SESSION['obj'] = $a;
> ?>
>
> In this case, when the object is going in the session, it naturally passes
> throught __sleep().
> The problem is that file_put_contents() doesn't work -> the file is not
> appended "OK\r\n" as it should be.
> "done!" is displayed , and if you look at the return value of
> file_put_contents ( number of bytes that have been written ) : it's all
> right ! It simply doesn not write to the file.
>
> Anyone has an idea ?
> Is this a bug ?
> Thx :)
>



-- 
Have A plesant Day
Chetan. D. Rane
Location: India
Contact: +91-9844922489
otherID: [EMAIL PROTECTED]
            [EMAIL PROTECTED]

--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Julien Pauli [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, November 20, 2007 3:51 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP] __sleep() strange behavior with file writting and
> SESSION using
> 
> Consider that very simple code, that runs on PHP 5.2.5 onto a Windows
> machine :
> <?php
> class a
> {
>     public $b;
> 
>     public function __sleep()
>     {
>         file_put_contents("log.txt","ok" . PHP_EOL,FILE_APPEND);
>         echo "done!";
>         return array();
>     }
> }
> 
> $a = new a;
> serialize($a);
> ?>
> 
> No problem here, log.txt is writtable, when it passes on the
> serialize()
> instruction, it goes to __sleep and works well.
> "OK\r\n" is appended to the log file , and "done!" is displayed.
> 
> 
> 
> Now consider this :
> 
> <?php
> session_start();
> class a
> {
>     public $b;
> 
>     public function __sleep()
>     {
>         file_put_contents("log.txt","ok" . PHP_EOL,FILE_APPEND);
>         echo "done!";
>         return array();
>     }
> }
> 
> $a = new a;
> $_SESSION['obj'] = $a;
> ?>
> 
> In this case, when the object is going in the session, it naturally
> passes
> throught __sleep().
> The problem is that file_put_contents() doesn't work -> the file is not
> appended "OK\r\n" as it should be.
> "done!" is displayed , and if you look at the return value of
> file_put_contents ( number of bytes that have been written ) : it's all
> right ! It simply doesn not write to the file.
> 
> Anyone has an idea ?
> Is this a bug ?
> Thx :)

Maybe I drank too much coffee last night, but this is working for me if I
add dirname(__FILE__) to "log.txt" (PHP version 5.2.4) and not otherwise

<?php
session_start();
class a
{
    public $b;

    public function __sleep()
    {
        file_put_contents(dirname(__FILE__)."/log.txt","ok" .
PHP_EOL,FILE_APPEND);
        echo "done!";
        return array();
    }
}

$a = new a;
$_SESSION['obj'] = $a;
?>

--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Andrés Robinet [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, November 20, 2007 7:41 PM
> To: [EMAIL PROTECTED]
> Subject: RE: [PHP] __sleep() strange behavior with file writting and
> SESSION using
> 
> > -----Original Message-----
> > From: Julien Pauli [mailto:[EMAIL PROTECTED]
> > Sent: Tuesday, November 20, 2007 3:51 PM
> > To: [EMAIL PROTECTED]
> > Subject: [PHP] __sleep() strange behavior with file writting and
> > SESSION using
> >
> > Consider that very simple code, that runs on PHP 5.2.5 onto a Windows
> > machine :
> > <?php
> > class a
> > {
> >     public $b;
> >
> >     public function __sleep()
> >     {
> >         file_put_contents("log.txt","ok" . PHP_EOL,FILE_APPEND);
> >         echo "done!";
> >         return array();
> >     }
> > }
> >
> > $a = new a;
> > serialize($a);
> > ?>
> >
> > No problem here, log.txt is writtable, when it passes on the
> > serialize()
> > instruction, it goes to __sleep and works well.
> > "OK\r\n" is appended to the log file , and "done!" is displayed.
> >
> >
> >
> > Now consider this :
> >
> > <?php
> > session_start();
> > class a
> > {
> >     public $b;
> >
> >     public function __sleep()
> >     {
> >         file_put_contents("log.txt","ok" . PHP_EOL,FILE_APPEND);
> >         echo "done!";
> >         return array();
> >     }
> > }
> >
> > $a = new a;
> > $_SESSION['obj'] = $a;
> > ?>
> >
> > In this case, when the object is going in the session, it naturally
> > passes
> > throught __sleep().
> > The problem is that file_put_contents() doesn't work -> the file is
> not
> > appended "OK\r\n" as it should be.
> > "done!" is displayed , and if you look at the return value of
> > file_put_contents ( number of bytes that have been written ) : it's
> all
> > right ! It simply doesn not write to the file.
> >
> > Anyone has an idea ?
> > Is this a bug ?
> > Thx :)
> 
> Maybe I drank too much coffee last night, but this is working for me if
> I
> add dirname(__FILE__) to "log.txt" (PHP version 5.2.4) and not
> otherwise
> 
> <?php
> session_start();
> class a
> {
>     public $b;
> 
>     public function __sleep()
>     {
>         file_put_contents(dirname(__FILE__)."/log.txt","ok" .>
PHP_EOL,FILE_APPEND);
>         echo "done!";
>         return array();
>     }
> }
> 
> $a = new a;
> $_SESSION['obj'] = $a;
> ?>
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

Just wanted to add, I found a log.txt at "D:\xampp\apache" which happens to
be the root of the apache installation on my system... so, moral of the
story, the current dir is not always the script's dir.
dirname(__FILE__)."/log.txt" will do the trick.

Rob

--- End Message ---
--- Begin Message ---
Andrés Robinet wrote:
>> -----Original Message-----

...

>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> Just wanted to add, I found a log.txt at "D:\xampp\apache" which happens to
> be the root of the apache installation on my system... so, moral of the
> story, the current dir is not always the script's dir.
> dirname(__FILE__)."/log.txt" will do the trick.

I was stumped when originally reading your question. I guess I glossed
over the fact that you weren't using an absolute path for the log file.

the problem makes sense - the CWD is the directory of the script that was 
called,
but during the startup/shutdown phases of php there is no script, the CWD is 
then
whatever the CWD is of the process that started php - apache in this case. 
additionally
some code may change the CWD and there maybe countless of other factors that 
could effect
it.

I suggest always using absolute paths - of only to avoid little mind-benders 
like this.

:-)

> 
> Rob
> 

--- End Message ---
--- Begin Message ---
[snip]
I wrote about this a long time ago ... In a galaxy far far away...

http://www.thelonecoder.com/Blog/?p=7

Be good lemmings and do as you're told...
[/snip]

Sitting squarely on the fence he is....

--- End Message ---
--- Begin Message ---
Who says you can't please them all... ;)


--
Stephen Johnson c | eh
The Lone Coder

http://www.thelonecoder.com
continuing the struggle against bad code

http://www.thumbnailresume.com
--




> From: Jay Blanchard <[EMAIL PROTECTED]>
> Date: Tue, 20 Nov 2007 14:25:21 -0600
> To: Stephen Johnson <[EMAIL PROTECTED]>, <[EMAIL PROTECTED]>
> Conversation: [PHP] two small issues with php mail OT
> Subject: RE: [PHP] two small issues with php mail OT
> 
> [snip]
> I wrote about this a long time ago ... In a galaxy far far away...
> 
> http://www.thelonecoder.com/Blog/?p=7
> 
> Be good lemmings and do as you're told...
> [/snip]
> 
> Sitting squarely on the fence he is....
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

--- End Message ---
--- Begin Message ---
Stephen Johnson wrote:
> Who says you can't please them all... ;)
> 

Erin Brokovich.

> --
> Stephen Johnson c | eh
> The Lone Coder
> 
> http://www.thelonecoder.com
> continuing the struggle against bad code
> 
> http://www.thumbnailresume.com
> --
> 
> 
> 
> 
>> From: Jay Blanchard <[EMAIL PROTECTED]>
>> Date: Tue, 20 Nov 2007 14:25:21 -0600
>> To: Stephen Johnson <[EMAIL PROTECTED]>, <[EMAIL PROTECTED]>
>> Conversation: [PHP] two small issues with php mail OT
>> Subject: RE: [PHP] two small issues with php mail OT
>>
>> [snip]
>> I wrote about this a long time ago ... In a galaxy far far away...
>>
>> http://www.thelonecoder.com/Blog/?p=7
>>
>> Be good lemmings and do as you're told...
>> [/snip]
>>
>> Sitting squarely on the fence he is....
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
> 

--- End Message ---
--- Begin Message ---
On Wednesday 21 November 2007 00:53:14 Jochem Maas wrote:
> Stephen Johnson wrote:
> > Who says you can't please them all... ;)
>
> Erin Brokovich.

nah you sure? why cant i remember that.
must be that early  altzheimers syndrome or something

>
> > --
> > Stephen Johnson c | eh
> > The Lone Coder
> >
> > http://www.thelonecoder.com
> > continuing the struggle against bad code
> >
> > http://www.thumbnailresume.com
> > --
> >
> >> From: Jay Blanchard <[EMAIL PROTECTED]>
> >> Date: Tue, 20 Nov 2007 14:25:21 -0600
> >> To: Stephen Johnson <[EMAIL PROTECTED]>,
> >> <[EMAIL PROTECTED]> Conversation: [PHP] two small issues with
> >> php mail OT
> >> Subject: RE: [PHP] two small issues with php mail OT
> >>
> >> [snip]
> >> I wrote about this a long time ago ... In a galaxy far far away...
> >>
> >> http://www.thelonecoder.com/Blog/?p=7
> >>
> >> Be good lemmings and do as you're told...
> >> [/snip]
> >>
> >> Sitting squarely on the fence he is....
> >>
> >> --
> >> PHP General Mailing List (http://www.php.net/)
> >> To unsubscribe, visit: http://www.php.net/unsub.php



-- 
---
Børge Holen
http://www.arivene.net

--- End Message ---

Reply via email to