Author Topic: Can you all run a quick little PHP test for me?  (Read 2379 times)

Mike

  • Jackass In Charge
  • Posts: 11257
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Can you all run a quick little PHP test for me?
« on: August 12, 2008, 08:06:23 PM »
Ok only for PHP 5 as it won't work in PHP 4 :)

Code: [Select]
<?php

class foo
{
private $name;

function __construct($name)
{
$this->name $name;
echo $this->name' '__FUNCTION__'<br />';
}

function __destruct()
{
echo $this->name' '__FUNCTION__'<br />';
}
}

class 
bar
{
private $ref;
private $name;

function __construct($name, &$ref null)
{
$this->name $name;
if (isset($ref))
$this->ref = &$ref;

echo $this->name' '__FUNCTION__'<br />';
}

function __destruct()
{
echo $this->name' '__FUNCTION__'<br />';
}
}

$f1 = new foo('f1');
$b1 = new bar('b1');
$f2 = new foo('f2');
$b2 = new bar('b2');

$b3 = new bar('b3'$f1);
$b4 = new bar('b4', new foo('Unnamed foo'));

echo 
'<br />';
?>

Result I get is:
Code: [Select]
f1 __construct
b1 __construct
f2 __construct
b2 __construct
b3 __construct
Unnamed foo __construct
b4 __construct

b4 __destruct
Unnamed foo __destruct
b3 __destruct
b2 __destruct
f2 __destruct
b1 __destruct
f1 __destruct

Do you all get the same results?

JaWiB

  • definitelys definately no MacGyver
  • Jackass V
  • Posts: 1443
  • Karma: +57/-4
Re: Can you all run a quick little PHP test for me?
« Reply #1 on: August 12, 2008, 08:51:51 PM »
I'm getting the same thing running php 5.2.3

Steve

  • This 49%er supports Romney
  • Just a Jackass
  • *
  • Posts: 16120
  • Karma: +31/-410
  • Mr. Mom
Re: Can you all run a quick little PHP test for me?
« Reply #2 on: August 12, 2008, 09:28:08 PM »
I'm getting the same thing running php 5.2.3

ditto
hey ethic if you and i were both courting lily allen..... oh wait, which one of us has a relationship that lasted more than the bus ride home?

webwhy

  • Jackass IV
  • Posts: 608
  • Karma: +15/-10
Re: Can you all run a quick little PHP test for me?
« Reply #3 on: August 12, 2008, 10:43:45 PM »
Same results on Hardy using
Code: [Select]
PHP 5.2.4-2ubuntu5.3 with Suhosin-Patch 0.9.6.2 (cli) (built: Jul 23 2008 06:44:49)
« Last Edit: August 12, 2008, 10:55:14 PM by webwhy »

webwhy

  • Jackass IV
  • Posts: 608
  • Karma: +15/-10
Re: Can you all run a quick little PHP test for me?
« Reply #4 on: August 12, 2008, 10:52:16 PM »
Different results on Dapper running
Code: [Select]
PHP 5.1.2 (cli) (built: Jul 23 2008 17:01:53)
Results
Code: [Select]
f1 __construct
b1 __construct
f2 __construct
b2 __construct
b3 __construct
Unnamed foo __construct
b4 __construct

f1 __destruct
b1 __destruct
f2 __destruct
b2 __destruct
b3 __destruct
b4 __destruct
Unnamed foo __destruct

Mike

  • Jackass In Charge
  • Posts: 11257
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: Can you all run a quick little PHP test for me?
« Reply #5 on: August 12, 2008, 11:26:27 PM »
Thanks.  A little bit of searching brought be back to the manual which says objects are destroyed in any order during shutdown.