rfc:autoboxing

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:autoboxing [2010/05/05 16:28] – Supply sample code and fix a typo. moriyoshirfc:autoboxing [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 3: Line 3:
   * Date: 2010-05-04   * Date: 2010-05-04
   * Author: Moriyoshi Koizumi <moriyoshi@php.net>   * Author: Moriyoshi Koizumi <moriyoshi@php.net>
-  * Status: Under Discussion+  * Status: Inactive
   * First Published at: http://wiki.php.net/rfc/autoboxing   * First Published at: http://wiki.php.net/rfc/autoboxing
-  * Other formats .. 
  
 ===== Introduction ===== ===== Introduction =====
Line 80: Line 79:
  
 ===== Discussions ===== ===== Discussions =====
-==== Exception on infeasible conversion ==== 
-[[http://news.php.net/php.internals/48204|Pas wrote]]: 
-> It could throw an exception. 
- 
-==== Relation to SPL Type library ==== 
-[[http://news.php.net/php.internals/48196|Daniel Egeberg wrote]]: 
-> Is there any reason why primitives couldn't be autoboxed to SplInt, SplBool, etc.((http://php.net/manual/book.spl-types.php))? These classes could maybe even be extended with method aliases to the relevant functions in PHP's library. 
- 
-==== Efficiency ==== 
-[[http://news.php.net/php.internals/48209|Dmitry Stogov wrote]]: 
-> I am afraid, this magic method will make php slower even if scripts don't use this future (at least the patch   disables code specialization for ZEND_INIT_METHOD_CALL) and make some future type propagation optimizations non-applicable.  
- 
 ==== Conflicts between libraries that utilizes this feature ==== ==== Conflicts between libraries that utilizes this feature ====
 [[http://news.php.net/php.internals/48195|Cornelious wrote]]: [[http://news.php.net/php.internals/48195|Cornelious wrote]]:
Line 103: Line 90:
  
 === Possible fix === === Possible fix ===
-  * Per-namespace autoboxing rules (like extension methods in C#) +  * Per-namespace autoboxing rules (like extension methods in C#) -- The idea is to allow namespaces to have each ''%%__autobox()%%'' magic method and limiting the scope where it takes effect to the namespace in which it is declared or used through ''use'' statement
-    The idea is to allow namespaces to have each ''%%__autobox()%%'' magic method and limiting the scope where it takes effect to the namespace in which it is declared or used through ''use'' statement.+ 
 +==== Relation to the existing PECL libraries ====  
 +[[http://news.php.net/php.internals/48196|Daniel Egeberg wrote]]: 
 +> Is there any reason why primitives couldn't be autoboxed to SplInt, SplBool, etc.((http://php.net/manual/book.spl-types.php))? These classes could maybe even be extended with method aliases to the relevant functions in PHP's library.
  
-==== Good place is runkit ==== 
 [[http://news.php.net/php.internals/48202|Brian Moon wrote]]: [[http://news.php.net/php.internals/48202|Brian Moon wrote]]:
 > I liken this to pecl/runkit. "For all those things you.... probably  shouldn't have been doing anyway". It will create a world where scripts are not portable. And if you need that for your internal project, that is fine. But, having this as part of the PHP core would be a disaster. This is even more heinous than %%__autoload()%%, IMO. SPL fixed this for autoload. I would support an SPL extenstion to treat primitive types as SPL objects. They are standardized. Not random. > I liken this to pecl/runkit. "For all those things you.... probably  shouldn't have been doing anyway". It will create a world where scripts are not portable. And if you need that for your internal project, that is fine. But, having this as part of the PHP core would be a disaster. This is even more heinous than %%__autoload()%%, IMO. SPL fixed this for autoload. I would support an SPL extenstion to treat primitive types as SPL objects. They are standardized. Not random.
  
- +==== Efficiency ==== 
-==== Context information to the callback ==== +[[http://news.php.net/php.internals/48209|Dmitry Stogov wrote]]: 
-[[http://news.php.net/php.internals/48199|Benjamin Eberlei wrote]]: +I am afraidthis magic method will make php slower even if scripts don't use this future (at least the patch   disables code specialization for ZEND_INIT_METHOD_CALL) and make some future type propagation optimizations non-applicable
-Should'nt any autobox callback should not only recieve the value to be autoboxedbut also the context information? I.e. the method name to be called on the variable? otherwise you cannot decide between different behaviours.+
  
 ==== Magic functions considered harmful ==== ==== Magic functions considered harmful ====
Line 120: Line 108:
 ]]))). ]]))).
  
 +==== Context information to the callback ====
 +[[http://news.php.net/php.internals/48199|Benjamin Eberlei wrote]]:
 +> Should'nt any autobox callback should not only recieve the value to be autoboxed, but also the context information? I.e. the method name to be called on the variable? otherwise you cannot decide between different behaviours.
 +
 +==== Exception on infeasible conversion ====
 +[[http://news.php.net/php.internals/48204|Pas wrote]]:
 +> It could throw an exception.
  
 ===== Patch ===== ===== Patch =====
 A preliminary patch (may be a bit outdated) is available at http://gist.github.com/162517 . A preliminary patch (may be a bit outdated) is available at http://gist.github.com/162517 .
  
-===== Changelog =====+===== Discussion on the List =====
  
 +  - 2005-02-09 : [[http://markmail.org/message/2bnwe77ie3yhc65i|Similar discussion back in 2005]]  
 +  - 2010-05-03 : [[http://markmail.org/message/a3df3nt7hyn4qsne|Initial discussion about this RFC]]
 +
 +===== Changelog =====
 2010-05-04: initial version 2010-05-04: initial version
 +
rfc/autoboxing.1273076910.txt.gz · Last modified: 2017/09/22 13:28 (external edit)