Bug #69718 [Com]: Return values for magics can be nonsensical

From: Date: Sun, 26 Apr 2020 03:14:24 +0000
Subject: Bug #69718 [Com]: Return values for magics can be nonsensical
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226773@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69718&edit=1

 ID:                 69718
 Comment by:         carusogabriel@php.net
 Reported by:        stas@php.net
 Summary:            Return values for magics can be nonsensical
 Status:             Assigned
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   *
 PHP Version:        master-Git-2015-05-28 (Git)
 Assigned To:        carusogabriel
 Block user comment: N
 Private report:     N

 New Comment:

> __set_state - only array is allowed as argument type

Btw, as reported via Bug #79521, this is not actually the case, we can return mixed.


Previous Comments:
------------------------------------------------------------------------
[2020-04-26 03:06:10] requinix@php.net

Related To: Bug #79521

------------------------------------------------------------------------
[2019-05-31 03:38:42] carusogabriel@php.net

The following pull request has been associated:

Patch Name: Ensure correct signatures for magic methods
On GitHub:  https://github.com/php/php-src/pull/4177
Patch:      https://github.com/php/php-src/pull/4177.patch

------------------------------------------------------------------------
[2015-05-28 07:05:21] stas@php.net

Description:
------------
Since we now allow defining return value types for functions, one can also create definition for
magic functions that make no sense, such as __toString() : float or __isset() : Closure. I think we
should restrict such definitions - either to types that makes sense or in case of methods that
aren't supposed to return anything useful, completely. We already do this for ctors, dtors and
__clone but not consistently for other magics.

Specifically, the following should be true:

__clone - no return type
__isset - only boolean allowed as return type
__sleep - only array allowed as return type
__set - no return type
__toString - only string allowed as return type
__wakeup - no return type

Also, may make sense to restrict argument types (of course, not typing is always ok):

__call/__callStatic - only string for first and array for second arguments
__get/__set/__isset/__unset - only string for the first argument

__set_state - only array is allowed as argument type





------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=69718&edit=1


Thread (4 messages)

« previous php.bugs (#226773) next »