FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » out of sheer curiosity...
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: out of sheer curiosity... [message #177549 is a reply to message #177546] Mon, 09 April 2012 09:29 Go to previous messageGo to previous message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma:
Senior Member
Am 09.04.2012 02:24, schrieb Jerry Stuckle:
> On 4/8/2012 6:39 PM, M. Strobel wrote:
>> Am 08.04.2012 23:15, schrieb Jerry Stuckle:
>>> On 4/8/2012 4:50 PM, M. Strobel wrote:
>>>> Am 29.03.2012 22:11, schrieb Jerry Stuckle:
>>>> > On 3/29/2012 10:21 AM, Erwin Moller wrote:
>>>> >> On 3/29/2012 3:39 PM, Jerry Stuckle wrote:
>>>> >>> On 3/29/2012 8:33 AM, Erwin Moller wrote:
>>>> >>>> On 3/29/2012 12:46 PM, The Natural Philosopher wrote:
>>>> >>
>>>> >> <snip>
>>>> >>
>>>> >>>>> Its just another way of doing things and I let my understanding of the
>>>> >>>>> problem guide me, not a set of arbitrary rules.
>>>> >>>>
>>>> >>>> As it should!
>>>> >>>>
>>>> >>>> But what 'rules' are you referring to?
>>>> >>>>
>>>> >>>> PHP's OO is pretty straightforward.
>>>> >>>> I think they did a decent job implementing OO.(php 5 that is)
>>>> >>>>
>>>> >>>> Creating smart classes is up to the programmer.
>>>> >>>> I am not aware of any extra 'rules'.
>>>> >>>>
>>>> >>>> Are you maybe referring to all kinds of design patterns scattered around
>>>> >>>> the web?
>>>> >>>> (In which case I tend to agree, because implementing other people's
>>>> >>>> solutions can take the fun out of programming. But reading them never
>>>> >>>> hurts. And when you agree to a certain approach you can even decide to
>>>> >>>> follow it yourself. It is all up to you, the programmer.)
>>>> >>>>
>>>> >>>
>>>> >>> Any rules TNP doesn't bother to understand are "arbitrary" in his mind.
>>>> >>> He doesn't even like having to follow PHP syntax rules - as he has also
>>>> >>> said in the past.
>>>> >>>
>>>> >>> But I disagree that PHP 5's implementation of OO is decent. I think it's
>>>> >>> half-assed at best. Truly written by people who have no understanding of
>>>> >>> OO. But then that can be said of a lot of PHP.
>>>> >>>
>>>> >>
>>>> >> Jerry,
>>>> >>
>>>> >> What are your main objections to the PHP5's OO approach?
>>>> >>
>>>> >> For myself: I must say I love its simplicity.
>>>> >> (Simplicity is a Good Thing in my opinion.)
>>>> >>
>>>> >>
>>>> >
>>>> > Well, to start with, the lack of function overloading. It is quite a good
>>>> > feature to
>>>> > be able to overload functions - especially constructors. And because of that, you
>>>> > have to run through all kinds of hoops when doing things like storing an object in
>>>> > the $_SESSION.
>>>> >
>>>> > Even then it doesn't work. When you store an object in the $_SESSION, the object's
>>>> > destructor is called at the end of the script, but on the next script the
>>>> > constructor
>>>> > is never called. A direct violation of OO principles.
>>>>
>>>> Works fine here. Test script:
>>>> #!/usr/local/bin/php
>>>> <?php
>>>>
>>>> class C1 {
>>>> public $var1 = 'M.';
>>>> public $var2 = 'Strobel';
>>>> function __construct() {
>>>> echo "\t--> call ". __METHOD__.PHP_EOL;
>>>> }
>>>> function __destruct() {
>>>> echo "\t--> call ". __METHOD__.PHP_EOL;
>>>> }
>>>> function __sleep() {
>>>> echo "\t--> call ". __METHOD__.PHP_EOL;
>>>> return array('var1','var2');
>>>> }
>>>> function __wakeup() {
>>>> echo "\t--> call ". __METHOD__.PHP_EOL;
>>>> }
>>>> } // end class C1
>>>>
>>>> echo "----- creating class\n";
>>>> $c = new C1;
>>>> echo "----- serializing class\n";
>>>> $ser = serialize($c);
>>>> echo "----- deserializing class\n";
>>>> $cc = unserialize($ser);
>>>> echo "----- deleting first class\n";
>>>> unset($c);
>>>> echo "----- deleting unserialized class\n";
>>>> unset($cc);
>>>> exit(0);
>>>> #-----------------------
>>>>
>>>> Result:
>>>> strobel@s114-intel:~/projekte/PHP> ./magicmethods.php
>>>> ----- creating class
>>>> --> call C1::__construct
>>>> ----- serializing class
>>>> --> call C1::__sleep
>>>> ----- deserializing class
>>>> --> call C1::__wakeup
>>>> ----- deleting first class
>>>> --> call C1::__destruct
>>>> ----- deleting unserialized class
>>>> --> call C1::__destruct
>>>>
>>>> What exactly did you criticize?
>>>>
>>>> /Str.
>>>
>>> Look at it again. You have two destructor calls but only one constructor call. A
>>> direct violation of OO principles.
>>>
>>> And BTW - I said nothing about serializing.
>>>
>>> You really do need to learn to read.
>>>
>>
>> No evasions, get to the point. I have one explicit constructor, and one wakeup which
>> is a constructor.
>>
>> What did you talk about if not about serializing?
>>
>> /Str.
>
> I know a one-to-one correspondence is very difficult for someone of your (lack of)
> intellect to understand, but I'll try again anyway.

This is evasion, or your troll rite.

> You have these calls:
> --> call C1::__construct
>
> That's ONE call to a constructor.
>
>
> --> call C1::__destruct
> --> call C1::__destruct
>
> That's TWO calls to destructors. IOW, an object was constructed without calling a
> constructor. This is a direct violation of OO principals (all objects must have
> exactly one constructor call and one destructor call).
>
> And ONE does not equal TWO. wakeup() is not a constructor, any more than sleep() is
> a destructor (and if sleep() were a destructor, then you would see a call to sleep()
> and a call to the destructor).

You should admit that serialize() is a special function that creates a frozen
portable copy of an object. The object loses it's identity in the process, but keeps
it's data. The calls to sleep() and wakeup() are okay.

> And I was referring to storing in a session, not serializing the data, i.e.
>
> $_SESSION['stupid'] = $idiot;

You could probably not work in a team, because you can't talk/write. You could
certainly not work as a teacher.

This is very interesting, and I never ran into this in my 20000+ lines of code
(current project), because I have a feeling of what makes sense. I always serialize
my objects myself.

The handling of objects in session variables seems broke. This is IMO no defect in
the object model, but in the session code.

Here is the test code, see yourself:

<head>
<title>object activity in session</title>
<meta http-equiv="content-type"
content="text/html;charset=utf-8" />
</head>
<body>
<h2>test script, see source code</h2>
<pre>
<?php
session_start();
if (!isset($_SESSION['cnt'])) $_SESSION['cnt']=1;
class C1 {
public $var1 = 'M. ';
public $var2 = 'Strobel';
function __construct() {
echo "\t--> call ". __METHOD__.PHP_EOL;
}
function __destruct() {
echo "\t--> call ". __METHOD__.PHP_EOL;
}
function __sleep() {
echo "\t--> call ". __METHOD__.PHP_EOL;
return array('var1','var2');
}
function __wakeup() {
echo "\t--> call ". __METHOD__.PHP_EOL;
}
function greet() { echo 'Hi, I am ',$this->var1, $this->var2, "\n"; }
} // end class C1

echo "This is call number ", $_SESSION['cnt'], "\n";

switch ($_SESSION['cnt']) {
case 1:
echo "creating object directly in session:\n";
$_SESSION['c1'] = new C1;
break;
case 2:
echo "Trying to access object in session:\n";
$_SESSION['c1']->greet();
break;
case 3:
echo "clearing session to start over, return code: ", session_destroy(), "\n";
break;
default:
echo "\nThis should not happen.\n";
}
$_SESSION['cnt']++;
?>
</pre></body></html>


/Str.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: 5.4 windows installer.
Next Topic: Does PHP5 treat $_SERVER['PHP_AUTH_USER']) differently?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 14:18:58 GMT 2024

Total time taken to generate the page: 0.12557 seconds