-
-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
__destruct is never called #489
Comments
we did not specify yet how to treat destructors - .NET has its own garbage collection and call to .NET finalizer is non-deterministic. Currently destructors are ignored. |
proposal for me: defining class : IDisposable {
private bool <disposed>;
~() {
((IDisposable)this).Dispose();
}
void IDisposable.Dispose() {
if (!<disposed>) {
<disposed> = true; this.__destruct();
}
}
} additionally; having |
use of __destruct is discouraged - different behavior than in PHP ref #489
- Finalize() method that calls __destruct() (through synthesized IDisposable.Dispose()) - Dispose() calls __destruct() just once - ref #489
Current state: |
To fully support PHP's destructors, we would need a deterministic GC. It is not planned for the Closing as won't be implemented, however; |
@jakubmisek Hi,__destruct seems to be never called,Is there any way to simple use it! <?php
//class Test implements \System\IDisposable
class Test
{
public function __construct()
{
echo 'hello';
}
/*
public function Dispose():void
{
$this->__destruct();
\System\GC::SuppressFinalize($this);
}
*/
public function __destruct()
{
echo 'bye';
file_put_contents(__DIR__.'/test.txt','byebye');
}
}
$o = new Test();
unset($o);//__destruct is never called
//while(true){
//sleep(3);
//} |
sadly we still have although, we should create .NET Finalizer and call |
Yes,I know why it is so difficult to implement __destuct! multi thread and destructor... |
I think we must call the __destruct function before the GC started. |
Sample:
PeachPie output:
PHP output:
Laravel uses __destruct in their Job queueing system, so jobs can't be queued now.
The text was updated successfully, but these errors were encountered: