rfc:boxingandunboxing

Differences

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

Link to this comparison view

Next revision
Previous revision
rfc:boxingandunboxing [2009/07/06 16:18]
schmalls created
rfc:boxingandunboxing [2017/09/22 13:28] (current)
Line 17: Line 17:
 The most obvious use for boxing is function and method type hints. The object type hints could be used to do implicit boxing of variables. Either a new magic method (''<​nowiki>​__</​nowiki>​box''​ for example) or a new interface (''​Boxable''​ for example) would need to be added to PHP. The boxing method would accept the scalar value and set its internal representation (similar to ''<​nowiki>​__</​nowiki>​wakeup''​). The method could either return false (and let PHP handle the failure) or throw an exception (''​BoxingException''​ for example) when the supplied value is not valid for the boxing operation. The most obvious use for boxing is function and method type hints. The object type hints could be used to do implicit boxing of variables. Either a new magic method (''<​nowiki>​__</​nowiki>​box''​ for example) or a new interface (''​Boxable''​ for example) would need to be added to PHP. The boxing method would accept the scalar value and set its internal representation (similar to ''<​nowiki>​__</​nowiki>​wakeup''​). The method could either return false (and let PHP handle the failure) or throw an exception (''​BoxingException''​ for example) when the supplied value is not valid for the boxing operation.
  
-It would be best for PHP to include as many object versions of scalar types as possible. The boxing functionality could be added to the SPL Types (([[http://.php.net/​manual/​en/​book.spl-types.php|SPL Types]])) to provide for standard representations of the scalar types. The power to box variables would also be available in userland classes.+It would be best for PHP to include as many object versions of scalar types as possible. The boxing functionality could be added to the SPL Types (([[http://​php.net/​manual/​en/​book.spl-types.php|SPL Types]])) to provide for standard representations of the scalar types. The power to box variables would also be available in userland classes.
  
 It could also be possible to try to perform implicit conversions from one object type to another, but the overhead of this feature may be too much. Consider it as an option only. It could also be possible to try to perform implicit conversions from one object type to another, but the overhead of this feature may be too much. Consider it as an option only.
rfc/boxingandunboxing.txt · Last modified: 2017/09/22 13:28 (external edit)