Is there a try-with-resource in PHP?

4

Is there something like PHP try with resource in Java? Or do I have to close resources in the block of finally same?

    
asked by anonymous 02.10.2018 / 05:03

2 answers

5

No, in essence you do not have to. One that PHP is a script language all runs for a few seconds, at most, is usually a fraction of this, so not releasing a feature makes no difference. And even if you need to release it soon enough you usually do it because the garbage collector is based on reference count, which allows a deterministic finalization, so once the object does not have a reference it is already collected and can release features, other than Java that has a crawl-based garbage collector, and the release can only occur when the GC kicks in, so you need another mechanism to release before, so try-resource has been created.

Unlike Java, PHP does not aptly, or did not have the exception-using culture in Java. And you do not have to do to release any feature (in almost all cases).

    
02.10.2018 / 05:12
-3

The small difference of the PHP language that is an untyped language, for other strongly typed languages, is that it is interpreted not needing to use the C # example, the using to free resource memory, while you execute a line of code it will automatically execute the line and release the resource as soon as the scope of the function terminates.

    
02.10.2018 / 15:36