1

With PHP's SessionHandler there is SessionHandler::write() which returns a value. The manual is somewhat vague about it:

Return Values

The return value (usually TRUE on success, FALSE on failure). Note this value is returned internally to PHP for processing.

(same for the interface)

I wonder what the meaning of that processing by PHP is.

I already was that clever and looked into session_set_save_handler but there the return value for the write() callback isn't even mentioned.

Community
  • 1
  • 1
hakre
  • 193,403
  • 52
  • 435
  • 836
  • When you var dump the value that is returned, what do you get? Maybe we can get a clue from there? Do you get a bool or something completely different? (I expect a bool since the docs say so, but maybe it gets even weirder? Wouldn't be the first time) – Jelmer Dec 27 '12 at 14:32
  • @Jelmer: It is not possible to `var_dump` the *returned* value. It is possible to `var_dump` the value before you return it however, for *that* value you can imagine any possible value. The question is what does PHP do with it? (To keep it simple: first step actually two values: `TRUE` and `FALSE`, in a secondary step, one could discuss all possible values including (but not limited to) *`FALSE`y* `simplexmlelement` objects). – hakre Dec 27 '12 at 14:40
  • may it be possible that it behaves the same as a mysqli object [(my question about this subject)](http://stackoverflow.com/questions/11284883/var-dump-of-result-gives-null-value-but-deeper-inspection-returns-a-integer)? I mean, it "keeps" the returned value in the "php core" until you actually use it. I think they mean that. Although I can't find the same phrase in the [mysqli::query docs](http://php.net/manual/en/mysqli.query.php). – Jelmer Dec 27 '12 at 16:20
  • @Jelmer: No. That are two different things here, you can not compare that. Here is a funtion in user-php code that returns a value to the binary, compiled php-core code that is currently interpreting the user-php code (a.k.a. user-callback calling from the PHP engine). I have the feeling you totally miss the overall picture here what that interface is for and how the callback works. – hakre Dec 27 '12 at 16:26
  • Yep indeed :) I am curious though, good luck. – Jelmer Dec 27 '12 at 18:50

1 Answers1

0

Well, "returned internally to PHP" in this context means: It is not passed back to your code (as the return type for session_write_close() is void.)

In other words, what PHP does with it should be treated as unknown (unless you look at the actual C source of PHP); thus I would simply follow the advice of returning true on success, and false if your custom session handler was somehow unable to write the session data.

If I should guess, I would say that maybe PHP generates a warning message, or maybe that ist just intended for use in a later version of PHP.

A way to find out would be to simply override SessionHandler::write() to always return false and see what happens. Check the console for any warnings.

fbitterlich
  • 882
  • 7
  • 24