php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #65664 __destruct act different when instantiate class with/out var
Submitted: 2013-09-12 22:48 UTC Modified: 2013-09-12 22:59 UTC
From: valentiny510 at yahoo dot es Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.4.19 OS: Secret :)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
9 + 50 = ?
Subscribe to this entry?

 
 [2013-09-12 22:48 UTC] valentiny510 at yahoo dot es
Description:
------------
When the class is instantiated with a variable is working like one espect...
but the issue come when you want to miss the variable, because you don't use it or whatever reason..

Can be possible to act the same way both times ?

Examples below..

Test script:
---------------
<?php
class Html
{
    function __construct( ) { echo "Header\n"; }
    function __construct( ) { echo "\nFooter"; }
}

# without variable
new Html;
<p>Some html here...</p>

# with $html var...
$html = new Html;
<p>Some html here...</p>


Expected result:
----------------
Header
Some html here...
Footer

Header
Some html here...
Footer


Actual result:
--------------
Header
Footer <-- This is the problem...
Some html here...

Header
Some html here...
Footer


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-09-12 22:59 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2013-09-12 22:59 UTC] nikic@php.net
The destructor is called when where are no more references to an object. In case of a temporary value (just new Html that isn't assigned) this will happen right after the expression is evaluated.
 [2013-09-12 23:15 UTC] valentiny510 at yahoo dot es
$html = new Html;
<-- From here to the end of script there is no more references to that object...
<p>Some html here...</p>

P.S. Thank you for answering so fast :)
 [2013-10-13 01:23 UTC] valentiny510 at yahoo dot es
I just realized that you changed the status to "Not a bug"..
It was a request not a bug submit, I think will be more appropiate something like "Wont be implemented" or the normal.. "Wont fix"
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 10:01:28 2024 UTC