Open RLievaart opened 2 years ago
Enums are a little different than objects in that they don't support session_start()
when the enum has not yet been defined. For other objects, PHP would create a __PHP_Incomplete_Class
instance. To fix this error, make sure the enum is either loaded or autoloadable when you call session_start()
.
I don't think this is properly documented so I'm converting this to a documentation issue.
Enums are a little different than objects in that they don't support
session_start()
when the enum has not yet been defined. For other objects, PHP would create a__PHP_Incomplete_Class
instance. To fix this error, make sure the enum is either loaded or autoloadable when you callsession_start()
.I don't think this is properly documented so I'm converting this to a documentation issue.
Thank you for explaining, there was nothing to find on either Google or php.net.
I just discovered: enums should be treated as classes when it comes to sessions. I.e. serialized. Especially since they can have methods.
This works fine:
<?php
session_start() ;
enum xxx {
case A;
case B;
case C;
function hello() {
echo "Hallo wereld";
}
}
if ( ! isset($_SESSION['test']) ) {
$_SESSION['test'] = serialize(xxx::C);
echo "Set.";
}
else {
$x = unserialize($_SESSION['test']) ;
echo $x == xxx::C ? "It's xxx::C\n" : "It's not xxx::C\n" ;
unserialize($_SESSION['test'])->hello() ;
unset($_SESSION['test']);
echo "Unset.";
}
Once this is documented, things will be clearer. Thank you for responding.
We'll keep this open until it's documented :slightly_smiling_face:
Ahhh, I apparantly pressed the wrong button, sorry!
Description
The following code:
When run TWICE!
Resulted SECOND TIME RUNNING in this output:
But I expected this output instead:
PHP Version
8.1.4
Operating System
Linux CentOs 7 -- 3.10.0-1160.59.1.el7.x86_64 php/php-src#1 SMP Wed Feb 23 16:47:03 UTC 2022 x86_64