Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #13035
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Object constructors/destructors |
| Date | 2014-02-28 11:03 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <leqc07$m8i$1@dont-email.me> (permalink) |
| References | (18 earlier) <530f759b$0$9503$9b4e6d93@newsspool1.arcor-online.net> <leo9iq$p2i$1@dont-email.me> <531094a4$0$9522$9b4e6d93@newsspool1.arcor-online.net> <leq591$9q6$1@dont-email.me> <5310b0b7$0$9503$9b4e6d93@newsspool1.arcor-online.net> |
On 2/28/2014 10:52 AM, Christoph Michael Becker wrote:
> Jerry Stuckle wrote:
>
>> On 2/28/2014 8:52 AM, Christoph Michael Becker wrote:
>>> Jerry Stuckle wrote:
>>>
>>>> On 2/27/2014 12:28 PM, Christoph Michael Becker wrote:
>>>>> Jerry Stuckle wrote:
>>>>>
>>>>>> On 2/26/2014 5:39 PM, Christoph Michael Becker wrote:
>>>>>>> Jerry Stuckle wrote:
>>>>>>>
>>>>>>>> No matter how you look at it, PHP's implementation violates OO
>>>>>>>> principles and works differently than any other OO language.
>>>>>>>
>>>>>>> You have claimed that often enough, but yet you have not brought any
>>>>>>> proof.
>>>>>>>
>>>>>>> E.g. what happens in Java if an object that implements the
>>>>>>> java.io.Serializable interface is given as argument to
>>>>>>> java.io.OutputStream.writeObject()? Is the destructor called?
>>>>>>>
>>>>>>
>>>>>> Yes, it is.
>>>>>
>>>>> I strongly doubt that. On one hand this would mean you can't use the
>>>>> object as soon as it has been written to the stream, and on the other
>>>>> hand there are no *destructors* in Java (finalize() is similar to a
>>>>> destructor, but it is not guaranteed that it will be called).
>>>>> Furthermore it depends on the garbage collector, when an object will be
>>>>> *destroyed*.
>>>>>
>>>>>> But when the new object is created, a constructor is
>>>>>> called. You cannot unserialize an object without a constructor being
>>>>>> called first.
>>>>>
>>>>> I doubt that, too. After all, java.io.ObjectInputStream.readObject()
>>>>> returns an object, which of course has to be *created* -- but
>>>>> there's no
>>>>> need to call its *constructor*.
>>>>>
>>>>
>>>> No, because the constructor is called automatically.
>>>
>>> Wrong, see below.
>>>
>>>>> However, I believe our dissent mainly stems from different use of
>>>>> terms.
>>>>> I am accustomed to understand constructor/destructor as user defined
>>>>> functions (which can be defined for custom initialization/finalization
>>>>> tasks), while this may not be the common definition.
>>>>>
>>>>
>>>> They may be user defined, or they may be defined by the system (as in
>>>> the absence of a user-defined constructor).
>>>>
>>>>> When you're talking about OO principles wrt. to
>>>>> construction/destruction, you're most likely referring to RAII,
>>>>> which is
>>>>> not necessarily a general OO principle, and might not be possible to be
>>>>> cleanly implemented in garbage collected languages generally (consider
>>>>> cyclic references).
>>>>>
>>>>
>>>> No, I am not referring to RAII. I am referring to basic OO principles.
>>>>
>>>>> Anyway, I somewhat consider this discussion as harping on about
>>>>> principles, and I still don't see that PHP lacks the really important
>>>>> concepts regarding object (de)serialization and cloning.
>>>>>
>>>>
>>>> Just that it doesn't follow OO principles - which has caused me problems
>>>> in the past.
>>>
>>> To shorten further discussion I have installed the JDK 7u51, and written
>>> the following classes:
>>>
>>> ---- Foo.java ----
>>> public class Foo implements java.io.Serializable {
>>> protected int bar;
>>> public Foo() {
>>> System.out.println("Constructor of Foo called");
>>> bar = 0;
>>> }
>>> public int getBar() {
>>> return bar;
>>> }
>>> public void setBar(int value) {
>>> bar = value;
>>> }
>>> }
>>>
>>> ---- Demo.java ----
>>> import java.io.*;
>>>
>>> public class Demo {
>>> public static void main(String[] args)
>>> throws IOException, ClassNotFoundException {
>>> Foo foo = new Foo();
>>> foo.setBar(42);
>>> FileOutputStream fileOut = new FileOutputStream("./ser");
>>> ObjectOutputStream out = new ObjectOutputStream(fileOut);
>>> out.writeObject(foo);
>>> out.close();
>>> fileOut.close();
>>> System.out.println("Serialized foo");
>>> System.out.print("bar = ");
>>> System.out.println(foo.getBar());
>>> foo = null;
>>> FileInputStream fileIn = new FileInputStream("./ser");
>>> ObjectInputStream in = new ObjectInputStream(fileIn);
>>> foo = (Foo) in.readObject();
>>> in.close();
>>> fileIn.close();
>>> System.out.println("Unserialized foo");
>>> System.out.print("bar = ");
>>> System.out.println(foo.getBar());
>>> }
>>> }
>>>
>>> To compare that with PHP's behavior, I've written the following script:
>>>
>>> ---- demo.php ----
>>> <?php
>>>
>>> class Foo
>>> {
>>> protected $bar;
>>> public function __construct() {
>>> echo "Constructor of Foo called\n";
>>> $this->bar = 0;
>>> }
>>> public function getBar() {
>>> return $this->bar;
>>> }
>>> public function setBar($value) {
>>> $this->bar = $value;
>>> }
>>> }
>>>
>>> $foo = new Foo();
>>> $foo->setBar(42);
>>> file_put_contents('./ser', serialize($foo));
>>> echo "Serialized foo\nbar = ", $foo->getBar(), "\n";
>>> $foo = null;
>>> $foo = unserialize(file_get_contents('./ser'));
>>> echo "Unserialized foo\nbar = ", $foo->getBar(), "\n";
>>>
>>> Running the java programm and the PHP script (PHP 5.4.19 cli) produces
>>> the following output:
>>>
>>> Constructor of Foo called
>>> Serialized foo
>>> bar = 42
>>> Unserialized foo
>>> bar = 42
>>>
>>> Any conclusions are left to the reader.
>>>
>>
>> Which shows just how little you understand programming.
>>
>> In either case you have not created a new Foo object before serializing;
>> you have only serialized into an existing object. So obviously no
>> constructor is called.
>
> Of course, I have created a new Foo object before serializing in both
> cases. You're probably talking about the unserializing code (please
> look up the difference), but in this case your statement is wrong, as I
> have assigned null to $foo (what would not have been necessary, though).
>
> However, maybe you want
>
> $foo = null;
>
> replaced by
>
> $foo = new Foo();
>
> (resp. for the Java code). While the only benefit of this change would
> be to keep the processor busy, it does no real harm (unless in a not
> garbage collected environment, where it would create a memory leak).
>
> So what do you think (or rather guess), the last line of the output
> would be when changing the code repectively? Answer: bar = 42. That
> proofs that the constructor is not called on the unserialized object.
>
> Anyway, both programs behave equivalent, so Java also does not follow
> basic OO principles wrt. to object (un)serialization, according to your
> claim. However, you have stated it would, so obviously there's a
> contradiction.
>
>> Your stoopidity is amazing.
>
> You may consider changing your attitude to not make a fool of you in the
> public, again.
>
Yes, you continue to make a fool of yourself in public - as your last
statement shows. You have absolutely NO idea what you are talking
about, or how OO works.
I correspond off-list with some knowledgeable people who have followed
this conversation. They can't believe I even try to educate you. It's
like teaching a pig to sing.
And I'm through wasting my time. Your comments aren't even worth a
response (which is why I also refused to fall into your trap as to how I
define an "expression").
You don't discuss. You argue for the sake of argument.
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Operator precedence Christoph Michael Becker <cmbecker69@arcor.de> - 2014-02-23 18:03 +0100
Re: Operator precedence GS <nomail@nospam.org.invalid> - 2014-02-23 19:42 +0000
Re: Operator precedence Christoph Michael Becker <cmbecker69@arcor.de> - 2014-02-23 21:23 +0100
Re: Operator precedence Jerry Stuckle <jstucklex@attglobal.net> - 2014-02-23 16:34 -0500
Re: Operator precedence Richard Damon <Richard@Damon-Family.org> - 2014-02-23 18:36 -0500
Re: Operator precedence Jerry Stuckle <jstucklex@attglobal.net> - 2014-02-23 21:09 -0500
Re: Operator precedence Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-02-24 04:49 +0000
Re: Operator precedence Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-02-24 12:56 +0100
Re: Operator precedence Christoph Michael Becker <cmbecker69@arcor.de> - 2014-02-24 17:38 +0100
Re: Operator precedence Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-02-24 21:25 +0000
Re: Operator precedence Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-02-25 00:38 +0100
Re: Operator precedence Christoph Michael Becker <cmbecker69@arcor.de> - 2014-02-25 01:07 +0100
Re: Operator precedence Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-02-25 01:37 +0100
Re: Operator precedence Christoph Michael Becker <cmbecker69@arcor.de> - 2014-02-25 02:12 +0100
Re: Operator precedence Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-02-25 03:29 +0100
Re: Operator precedence Christoph Michael Becker <cmbecker69@arcor.de> - 2014-02-25 19:41 +0100
Re: Operator precedence Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-02-25 19:55 +0100
Re: Operator precedence Christoph Michael Becker <cmbecker69@arcor.de> - 2014-02-25 21:36 +0100
Re: Operator precedence Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-02-25 03:08 +0000
Re: Operator precedence Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-02-25 04:17 +0100
Re: Operator precedence Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-02-25 04:45 +0000
Re: Operator precedence GS <nomail@nospam.org.invalid> - 2014-02-25 21:45 +0000
Re: Operator precedence Jerry Stuckle <jstucklex@attglobal.net> - 2014-02-24 07:00 -0500
Re: Operator precedence Christoph Michael Becker <cmbecker69@arcor.de> - 2014-02-24 18:11 +0100
Re: Operator precedence Jerry Stuckle <jstucklex@attglobal.net> - 2014-02-24 14:27 -0500
Re: Operator precedence Christoph Michael Becker <cmbecker69@arcor.de> - 2014-02-25 01:25 +0100
Re: Operator precedence Jerry Stuckle <jstucklex@attglobal.net> - 2014-02-24 20:40 -0500
Re: Operator precedence Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-02-24 21:23 +0000
Re: Operator precedence Jerry Stuckle <jstucklex@attglobal.net> - 2014-02-24 16:45 -0500
Re: Operator precedence Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-02-25 04:32 +0000
Re: Operator precedence Jerry Stuckle <jstucklex@attglobal.net> - 2014-02-24 23:47 -0500
Re: Operator precedence Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-02-25 16:56 +0000
Re: Operator precedence Jerry Stuckle <jstucklex@attglobal.net> - 2014-02-25 13:59 -0500
Re: Operator precedence Christoph Michael Becker <cmbecker69@arcor.de> - 2014-02-25 20:19 +0100
Re: Operator precedence Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-02-25 20:43 +0100
Re: Operator precedence Jerry Stuckle <jstucklex@attglobal.net> - 2014-02-25 16:02 -0500
Re: Operator precedence Jerry Stuckle <jstucklex@attglobal.net> - 2014-02-25 16:01 -0500
Object constructors/destructors (was: Operator precedence) Christoph Michael Becker <cmbecker69@arcor.de> - 2014-02-25 22:19 +0100
Re: Object constructors/destructors Jerry Stuckle <jstucklex@attglobal.net> - 2014-02-25 16:32 -0500
Re: Object constructors/destructors Christoph Michael Becker <cmbecker69@arcor.de> - 2014-02-25 22:55 +0100
Re: Object constructors/destructors Jerry Stuckle <jstucklex@attglobal.net> - 2014-02-25 17:01 -0500
Re: Object constructors/destructors Adam Harvey <usenet@adamharvey.name> - 2014-02-25 23:22 +0000
Re: Object constructors/destructors Jerry Stuckle <jstucklex@attglobal.net> - 2014-02-25 21:10 -0500
Re: Object constructors/destructors Christoph Michael Becker <cmbecker69@arcor.de> - 2014-02-26 21:10 +0100
Re: Object constructors/destructors Jerry Stuckle <jstucklex@attglobal.net> - 2014-02-26 16:01 -0500
Re: Object constructors/destructors Christoph Michael Becker <cmbecker69@arcor.de> - 2014-02-26 22:59 +0100
Re: Object constructors/destructors Jerry Stuckle <jstucklex@attglobal.net> - 2014-02-26 17:19 -0500
Re: Object constructors/destructors Christoph Michael Becker <cmbecker69@arcor.de> - 2014-02-26 23:39 +0100
Re: Object constructors/destructors Jerry Stuckle <jstucklex@attglobal.net> - 2014-02-26 22:30 -0500
Re: Object constructors/destructors Christoph Michael Becker <cmbecker69@arcor.de> - 2014-02-27 18:28 +0100
Re: Object constructors/destructors Jerry Stuckle <jstucklex@attglobal.net> - 2014-02-27 16:09 -0500
Re: Object constructors/destructors Christoph Michael Becker <cmbecker69@arcor.de> - 2014-02-28 14:52 +0100
Re: Object constructors/destructors Jerry Stuckle <jstucklex@attglobal.net> - 2014-02-28 09:08 -0500
Re: Object constructors/destructors Christoph Michael Becker <cmbecker69@arcor.de> - 2014-02-28 16:52 +0100
Re: Object constructors/destructors Jerry Stuckle <jstucklex@attglobal.net> - 2014-02-28 11:03 -0500
Re: Object constructors/destructors Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-02-27 01:00 +0100
Re: Object constructors/destructors Jerry Stuckle <jstucklex@attglobal.net> - 2014-02-26 22:39 -0500
Re: Object constructors/destructors Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-02-27 18:29 +0100
Re: Object constructors/destructors Jerry Stuckle <jstucklex@attglobal.net> - 2014-02-27 16:14 -0500
Re: Object constructors/destructors Christoph Michael Becker <cmbecker69@arcor.de> - 2014-02-26 00:18 +0100
Re: Object constructors/destructors Jerry Stuckle <jstucklex@attglobal.net> - 2014-02-25 21:08 -0500
Re: Object constructors/destructors Richard Damon <Richard@Damon-Family.org> - 2014-02-26 07:50 -0500
Re: Object constructors/destructors Jerry Stuckle <jstucklex@attglobal.net> - 2014-02-26 08:44 -0500
Re: Object constructors/destructors Richard Damon <Richard@Damon-Family.org> - 2014-02-26 23:49 -0500
Re: Object constructors/destructors Jerry Stuckle <jstucklex@attglobal.net> - 2014-02-27 08:25 -0500
Re: Object constructors/destructors Richard Damon <Richard@Damon-Family.org> - 2014-03-01 12:56 -0500
Re: Object constructors/destructors Jerry Stuckle <jstucklex@attglobal.net> - 2014-03-01 14:22 -0500
Re: Object constructors/destructors Richard Damon <Richard@Damon-Family.org> - 2014-03-02 14:28 -0500
Re: Object constructors/destructors Jerry Stuckle <jstucklex@attglobal.net> - 2014-03-02 15:42 -0500
Re: Object constructors/destructors Richard Damon <Richard@Damon-Family.org> - 2014-03-02 17:14 -0500
Re: Object constructors/destructors Jerry Stuckle <jstucklex@attglobal.net> - 2014-03-02 17:48 -0500
Re: Object constructors/destructors Tim Streater <timstreater@greenbee.net> - 2014-03-02 23:05 +0000
Re: Operator precedence Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-02-25 21:08 +0000
Re: Operator precedence Christoph Michael Becker <cmbecker69@arcor.de> - 2014-02-25 22:29 +0100
Re: Operator precedence Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-02-25 23:15 +0000
Re: Operator precedence Richard Damon <Richard@Damon-Family.org> - 2014-02-24 22:41 -0500
Re: Operator precedence Jerry Stuckle <jstucklex@attglobal.net> - 2014-02-24 23:59 -0500
Re: Operator precedence Richard Damon <Richard@Damon-Family.org> - 2014-03-01 13:39 -0500
Re: Operator precedence Jerry Stuckle <jstucklex@attglobal.net> - 2014-03-01 14:29 -0500
Re: Operator precedence Richard Damon <Richard@Damon-Family.org> - 2014-03-02 15:22 -0500
Re: Operator precedence Jerry Stuckle <jstucklex@attglobal.net> - 2014-03-02 15:49 -0500
Re: Operator precedence Christoph Michael Becker <cmbecker69@arcor.de> - 2014-02-25 19:15 +0100
Re: Operator precedence Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-02-23 20:56 +0000
Re: Operator precedence Christoph Michael Becker <cmbecker69@arcor.de> - 2014-02-24 14:28 +0100
csiph-web