Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why 'Serialization of 'SplFileInfo' is not allowed?

Tags:

php

I'm trying to store an array of SplFileInfo instances in a cache with serialize command but the command throws this exception:

Exception' with message 'Serialization of 'SplFileInfo' is not allowed

Why is it not allowed?

Thanks!

Note: I'm just curious. The problem itself can be worked around.

like image 768
Martin Vseticka Avatar asked Dec 09 '22 08:12

Martin Vseticka


1 Answers

Objects based on Resources can't be serialized.

I guess I don't have to explain why (if you need the explanation tell me even if it's OT in this question)

Addendum

For @Charles that doesn't believe that SplFileInfo doens't store/open a new resource I have made a little test script.

If you run this:

new SplFileInfo('index.php');
$link=mysql_connect('localhost','root','');
echo $link;

The output is: Resource id #2

If you run this:

//new SplFileInfo('index.php');
$link=mysql_connect('localhost','root','');
echo $link;

The output is: Resource id #1.

like image 95
dynamic Avatar answered Dec 28 '22 22:12

dynamic