hhvm icon indicating copy to clipboard operation
hhvm copied to clipboard

__destruct invalid?

Open huzhiguang opened this issue 14 years ago • 13 comments

hiphop complie php class's __destruct invalid? code follow as: ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

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.

huzhiguang avatar Sep 28 '12 05:09 huzhiguang

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

paroski avatar Sep 28 '12 05:09 paroski

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

huzhiguang avatar Sep 28 '12 06:09 huzhiguang

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

paroski avatar Sep 28 '12 06:09 paroski

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

huzhiguang avatar Sep 28 '12 06:09 huzhiguang

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

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

paroski avatar Sep 28 '12 06:09 paroski

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 [email protected]:

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

h4ck3rm1k3 avatar Sep 28 '12 06:09 h4ck3rm1k3

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

huzhiguang avatar Sep 28 '12 06:09 huzhiguang

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 [email protected]:

@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

h4ck3rm1k3 avatar Sep 28 '12 06:09 h4ck3rm1k3

@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.:(

huzhiguang avatar Sep 28 '12 06:09 huzhiguang

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

paroski avatar Sep 28 '12 07:09 paroski

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 <[email protected]

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

h4ck3rm1k3 avatar Sep 28 '12 08:09 h4ck3rm1k3

@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 avatar Sep 28 '12 08:09 huzhiguang

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

huzhiguang avatar Sep 28 '12 08:09 huzhiguang