Doc #79521 [Com]: Fix `__set_state` documentation

From: Date: Sun, 26 Apr 2020 03:39:09 +0000
Subject: Doc #79521 [Com]: Fix `__set_state` documentation
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-17520@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79521&edit=1 ID: 79521 Comment by: carusogabriel@php.net Reported by: carusogabriel@php.net Summary: Fix __set_state documentation Status: Open Type: Documentation Problem Package: Class/Object related PHP Version: Irrelevant Block user comment: N Private report: N New Comment: > Sorry, by ignored I meant that the type doesn't matter. :+1: > It really should return an object, though. It's what the method is for. In this case, we'd need an RFC removing that functionality, right? > And I totally didn't notice the RFC was yours. I'll shut up now :) Comments are always welcome, don't shut up ;) Previous Comments: ------------------------------------------------------------------------ [2020-04-26 03:26:30] requinix@php.net Sorry, by ignored I meant that the type doesn't matter. It really should return an object, though. It's what the method is for. And I totally didn't notice the RFC was yours. I'll shut up now :) ------------------------------------------------------------------------ [2020-04-26 03:14:24] carusogabriel@php.net Related To: Bug #69718 ------------------------------------------------------------------------ [2020-04-26 03:13:11] carusogabriel@php.net > It doesn't include __set_state, but this is likely just an oversight. Yeah, I'm working on that right now, that's why I come up with this bug report. > The return value is simply being ignored. Also not an error. It isn't: it does change the result based on the type: - https://3v4l.org/jt3jL (string) - https://3v4l.org/tIHi3 (object) This is supported by the engine: https://github.com/php/php-src/blob/d21d23afef54f152d9ca661909c6d042d6bfcf48/ext/standard/var.c#L472-L593 > and it is not an error to pass more arguments than are defined in a function signature. It is not an error, this is why the documentation needs to be updated, right? ------------------------------------------------------------------------ [2020-04-26 03:06:10] requinix@php.net The fact that you can get away without arguments is for the usual reasons: the signature of __set_state is not enforced by the engine, and it is not an error to pass more arguments than are defined in a function signature. The return value is simply being ignored. Also not an error. Related: the magic-methods-signature RFC https://wiki.php.net/rfc/magic-methods-signature It doesn't include __set_state, but this is likely just an oversight. See also bug #69718 ------------------------------------------------------------------------ [2020-04-26 02:59:47] carusogabriel@php.net Description: ------------ The documentation (https://php.net/manual/en/language.oop5.magic.php#object.set-state) of the magic method __set_state says: - it MUST take an array argument - it MUST return an object Ok, two problems: - it CAN take an argument, is not mandatory, e.g.: https://3v4l.org/gTlmV - it CAN return, is not mandatory: https://3v4l.org/SG8Hs Should we fix its documentation? Something like -static __set_state ( array $properties ) : object +static __set_state ( [array $properties] ) : mixed ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79521&edit=1

« previous php.doc.bugs (#17520) next »