PHP 8.5.3 Released!

resource

resource türünde bir değişken harici bir özkaynağa bir gönderim içeren özel bir değişkendir. Özkaynaklar özel işlevler tarafından oluşturulur ve kullanılırlar. resource türüyle ilişkilendirilebilen özkaynakların ve özel işlevlerin bir listesini eklerde bulabilirsiniz.

Ayrıca, get_resource_type() işlevine de bakınız.

resource türüne dönüşüm

Açık dosyalara, veritabanı bağlantılarına, görüntü tuval alanlarına ve benzerlerine birer tanıtıcı sağlayan değişkenleri resource türüne dönüştürmenin bir anlamı yoktur.

Özkaynakları serbest bırakmak

Zend Motoru sayesinde gönderimsiz kalan özkaynaklar otomatik olarak saptanarak bunlara ayrılan bellek çöp toplayıcı tarafından serbest bırakılmaktadır. Bu sebeple bir özkaynağa ayrılan belleği serbest bırakmak ihtiyacı nadiren ortaya çıkar.

Bilginize: Kalıcı veritabanı bağlantıları bu kuralın bir istisnasıdır. Çöp toplayıcı tarafından yok edilmezler. Bu konuda daha ayrıntılı bilgi edinmek için kalıcı bağlantılar bölümüne bakınız.

add a note

User Contributed Notes 1 note

up
1
mrmhmdalmalki at gmail dot com
21 hours ago
The resource is not a type you can create; it is a PHP internal type that PHP uses to refer to some variables.

For example, 

You have a number 5.5, which is a Float, and you can convert it to an int type, but you cannot convert it to a resource.

A resource type is used for external resources, like files or database connections, as shown below:

<?php

// a normal variable
$file_resource = fopen("normal_file.txt", "r");

// after we assigned an external file to that variable using the function fopen,
// PHP starts dealing with the file, and since it is an external resource,
// PHP makes the type of the variable a resource that refers to that operation

var_dump($file_resource);

// the previous var_dump returned bool(false),
// because there was no file that PHP could open.
// and it gave me this warning:
// PHP Warning: fopen(normal_file.txt): Failed to open stream: No such file or directory

// now I am trying to open an existing file
$file_resource = fopen("existed_file.txt", "r");

// then check the type:
var_dump($file_resource);

// it gives this:
// resource(5) of type (stream)
// now the variable's type is resource

?>
To Top