Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the PHP "resource" type? [closed]

Tags:

php

I'm just trying to deepen my understanding of the resource type, and I'm not really sure why it was invented in the first place.

From my experience, architecturally, you only ever send resources around as dependencies for other functions in the same operation in which you're executing, but you will never send that resource to a separate part of your program. Surely just a standard object would suffice?

Am I missing something? What is a resource / how should it be used?

like image 495
Will Morgan Avatar asked Jun 15 '12 16:06

Will Morgan


1 Answers

Before PHP 5, objects had by-value semantics. I.e., you passed them around like structs and their data were copied. That wouldn't have worked for something like a database or file handle. I'd guess that's why these resources were a distinct type.

like image 144
Boann Avatar answered Oct 01 '22 20:10

Boann