S
S
Sergey Pugovkin2017-06-02 21:45:25
PHP
Sergey Pugovkin, 2017-06-02 21:45:25

Why is it not recommended to set resource type constants in PHP?

php.net/manual/en/function.define.php

Warning
It is also possible to set resource type constants, but it is not recommended to do so as it can lead to unpredictable results.

What results are we talking about? There are examples?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Pavlenko, 2017-06-02
@Driver86

<?php
$file_handler = fopen('test_123456.php', 'a+');
define('FILE_HANDLER', $file_handler);
echo fgets(FILE_HANDLER, 50);
Well. The behavior is quite working on PHP 7.1. But the question is "why?" (I immediately recall a picture with a trolleybus made from a loaf of bread).
Therefore, they warn - yes, this can be done. Yes, sometimes it will work. But we cannot foresee all cases, so stay out of harm's way.

O
OnYourLips, 2017-06-02
@OnYourLips

The resource type in PHP is legacy from PHP3 times. This type is not valid.
Now you can only meet him with the old way of working with files (the result of running fopen).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question