facebook / hhvm

A virtual machine for executing programs written in Hack.
https://hhvm.com
Other
18.13k stars 2.99k forks source link

__destruct invalid? #604

Closed huzhiguang closed 11 years ago

huzhiguang commented 11 years ago

hiphop complie php class's destruct invalid? code follow as: //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// <?php class Test1{ public function construct(){}

    public function __destruct(){
        echo "-------------destruct2222";
    }

} $a=new Test1();

?> ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

this code run php environment no problem,out content "-------------destruct2222"",but run hiphop environment,Test1's destruct invalid,destruct function no call. please help me solve this problem, thanks very much.

paroski commented 11 years ago

By default, HipHop does not invoke __destruct methods on objects that are still live at the end of the request. This behavior and other inconsistencies are documented in "doc/inconsistencies".

If you explicitly remove all references to the object before the request ends (by setting $a to null, for example) the __destruct method will get called.

HipHop VM offers a runtime option "Eval.EnableObjDestructCall" which can be used to make HipHop call __destruct on all objects that are still live at the end of the request (though this feature is not super-well tested and hasn't been optimized for performance). hphpc does not support the "Eval.EnableObjDestructCall" runtime option.

You can enable runtime options by putting them in your HipHop config file, or by specifying them at the command line like so: hhvm -f <php file> -v Eval.EnableObjDestructCall=true

Hope this helps.

-Drew

huzhiguang commented 11 years ago

If I want to implement __destruct ,Do you have any good method?

paroski commented 11 years ago

Here is an example where the __destruct method will be called:

<?php class Test1 { public function construct() {} public function destruct(){ echo "-------------destruct2222"; } } $a=new Test1(); $a=null;

huzhiguang commented 11 years ago

I don't want to change PHP source code, can from hiphop source place to start? Because I see hiphop c + + class destructor no call don't know why? Please you give me some ideas,Thanks

paroski commented 11 years ago

Run your program using the "Eval.EnableObjDestructCall" runtime option like so:

hhvm -f <php file> -v Eval.EnableObjDestructCall=true

h4ck3rm1k3 commented 11 years ago

ok, of course you want to compile the code without changing it. the compiler should handle this. I will review some code and give you a pointer where you can start to change this in php. mike

On Fri, Sep 28, 2012 at 8:20 AM, huzhiguang notifications@github.comwrote:

I don't want to change PHP source code, can from hiphop source place to start? Because I see hiphop c + + class destructor no call don't know why? Please you give me some ideas,Thanks

James Michael DuPont Member of Free Libre Open Source Software Kosova http://flossk.org Saving wikipedia(tm) articles from deletion http://SpeedyDeletion.wikia.com Contributor FOSM, the CC-BY-SA map of the world http://fosm.org Mozilla Rep https://reps.mozilla.org/u/h4ck3rm1k3 Free Software Foundation Europe Fellow http://fsfe.org/support/?h4ck3rm1k3

huzhiguang commented 11 years ago

@paroski I didn't use HHVM, I use static compilation, do not know to have Eval. EnableObjDestructCall = true this parameter?

h4ck3rm1k3 commented 11 years ago

He is talking about the vm options, not a compiler option/ https://github.com/facebook/hiphop-php/blob/master/doc/inconsistencies

@huzhiguang i am still reviewing the source code for the desctructors, there are thousands and thousands of methods called destruct, i guess I will have to review them. :(

mike

On Fri, Sep 28, 2012 at 8:27 AM, huzhiguang notifications@github.comwrote:

@paroski https://github.com/paroski I didn't use HHVM, I use static compilation, do not know to have Eval. EnableObjDestructCall = true this parameter?

— Reply to this email directly or view it on GitHubhttps://github.com/facebook/hiphop-php/issues/604#issuecomment-8965789.

James Michael DuPont Member of Free Libre Open Source Software Kosova http://flossk.org Saving wikipedia(tm) articles from deletion http://SpeedyDeletion.wikia.com Contributor FOSM, the CC-BY-SA map of the world http://fosm.org Mozilla Rep https://reps.mozilla.org/u/h4ck3rm1k3 Free Software Foundation Europe Fellow http://fsfe.org/support/?h4ck3rm1k3

huzhiguang commented 11 years ago

@h4ck3rm1k3 I know @paroski talk about the vm options,but I want to use static compiler. so I want to have a way implement this function.:(

paroski commented 11 years ago

I see. HipHop static compilation (hphpc) does not support invoking __destruct on objects that are still live at the end of the request, sorry.

h4ck3rm1k3 commented 11 years ago

This is too much work for me right now, I will do some other more important things.

On Fri, Sep 28, 2012 at 8:33 AM, Mike Dupont <jamesmikedupont@googlemail.com

wrote:

i guess I will have to review them. :(

James Michael DuPont Member of Free Libre Open Source Software Kosova http://flossk.org Saving wikipedia(tm) articles from deletion http://SpeedyDeletion.wikia.com Contributor FOSM, the CC-BY-SA map of the world http://fosm.org Mozilla Rep https://reps.mozilla.org/u/h4ck3rm1k3 Free Software Foundation Europe Fellow http://fsfe.org/support/?h4ck3rm1k3

huzhiguang commented 11 years ago

@paroski and @h4ck3rm1k3 I looked at /src/runtime/ext/ext_memcache.h and ext_memcached.cpp , this files c_memcache class extend Sweepable,and ~c_memcache can out content.and then I give c_DummyClosure extend Sweepable can call ~c_DummyClosure . but I create c_Redis extend Sweepable , ~c_Redis can't out content. Please give me some idea and solve this problem,if this way can success,and then destruct is no problem. thanks

huzhiguang commented 11 years ago

this problem have solve ,extends Sweepable this class can call c++ destruct function Thanks @paroski and @h4ck3rm1k3 I will share this program:)