Is Try-with-Resource in PHP?

Asked

Viewed 98 times

4

Exists in PHP something similar to Try with Resource java? Or I have to close resources in the finally even?

2 answers

6


No, in essence it doesn’t. One that PHP is a language of script Everything runs for a few seconds, at best, usually a fraction of it, so not releasing a resource makes no difference. And even if I need to release him soon he usually does because the Garbage Collector of it is based on reference count, which allows a deterministic completion, so so as soon as the object does not have a reference to it is already collected and can release the resources, unlike Java which has a tracking-based garbage collector and release can only occur when the GC goes into action, so it needs another mechanism to release before, so it was created the try-resource.

Unlike Java, PHP does not have, rightly, or did not have the culture of using exceptions as in Java. And do not need to do to release any resource (in almost all cases).

  • Vlw Maniero I kill my doubt ;)

-4

The small difference from the PHP language which is an untyped language, to other strongly typed languages, is that it is interpreted not needing to use the example of C#, the use to free resource from memory, when you run a line of code it will automatically run the line and release the feature as soon as the scope of the function finishes.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.