Table of Contents

Request for Comments: Class casting to scalar

This RFC covers a way to cast classes to scalar values other than strings.


Currently the Zend Engine provides some magic to methods in classes with defined names, for example __toString() is called when someone attempts to cast a class to a string.

The purpose of this RFC is to propose a way to allow casting to other scalar types (boolean, double, integer).

Why casting?

For the same reasons as __toString() exists, casting to other types might be needed. Feature requests have been submitted regarding this in the past.

Possible features/implementations

Interface or magic method?

Currently two possibilities exists:

Pass requested type?

Concern has been raised over the fact of passing the requested value type as parameter to the function, as it could be used to disallow some kinds of cast.

Proposal and Patch

Rejected Features



2008-11-24: Initial draft