why doesn't it just substitute it with the name of the file?
You ask why converting "resource" to "string" not give you a filename? That has been programmed by PHP authors. I don't think it would be useful. You known what file/directory you opened (you just used it on the same line). On the other hand, you sometimes need to known this handle number.
If you ask why "opendir" command give you a "handle" and not a filename, because file names are inconvenient and unreliable in this situation. For example processes need to pass it to other processes. The string with file name and path can be long and every time it need to be copied byte by byte, first allocating appropriate memory for it. Better is using integer value, which coping is very, very fast for microprocessor.