Portability | portable |
---|---|
Stability | experimental |
Maintainer | Edward L. Blake <edwardlblake@gmail.com> |
Safe Haskell | Safe-Inferred |
Functions for performing conversion from PHPSessionValue
objects to Haskell
types while using a subset of the implicit PHP type coercion behaviour. Some
of the differences from the implicit type conversion found in PHP are noted:
- Conversions that are documented as undefined behaviour in the PHP manual will throw definite exceptions with these functions.
- A significant difference from PHP's conversion rules is that
NULL
cannot be directly converted to any data type except toBool
, otherwiseNULL
has to be handled by using the type
to capture nullable values.Maybe
a - Objects that implement Serializable are not convertible to any other type at all as their value systems are not directly interpretable in a meaningful manner.
- Numbers can be converted to strings, but only strings that satisfy
reads str = [(value, "")]
can be converted back to numbers. - Arrays and objects to string conversions which would normally be coerced to the simple strings "Array" and "Object" in PHP, are simply considered errors with these conversion functions.
- convFromPHPImplicit :: ConversionFromPHPImplicitValueOrMismatch b => PHPSessionValue -> b
- convFromPHPImplicitSafe :: ConversionFromPHPImplicitValueOrMismatch b => PHPSessionValue -> Either String b
- class ConversionFromPHPImplicitValueOrMismatch b where
- convFromPHPImplicitOM :: PHPSessionValue -> Either String b
Convert from PHPSessionValue
convFromPHPImplicit :: ConversionFromPHPImplicitValueOrMismatch b => PHPSessionValue -> bSource
convFromPHPImplicit
and convFromPHPImplicitSafe
are functions that convert
values stored as PHPSessionValue
into appropriate Haskell types depending on
the desired type cast or inferred. Unlike the convFrom
and convFromSafe
functions provided in Data.PHPSession.Conv, functions provided in this module
perform type coercion based on a significant number of conversion rules to
satisfy the type cast or inferred.
The example arrayOfPHPStrings
definition given in the example documented in
Data.PHPSession.Conv can be evaluated to [(0,"Hello"),(1,"World")]
.
>>>
convFromPHPImplicit arrayOfPHPStrings :: [(Int,LBS.ByteString)]
[(0,"Hello"),(1,"World")]
However, if the desired type signature is changed:
>>>
convFromPHPImplicit arrayOfPHPStrings :: [(LBS.ByteString,LBS.ByteString)]
[("0","Hello"),("1","World")]
Where there is the possibility that the value being sought may be NULL
, the
type should be (
.
Maybe
a)
convFromPHPImplicitSafe :: ConversionFromPHPImplicitValueOrMismatch b => PHPSessionValue -> Either String bSource
convFromPHPImplicitSafe
is a version of convFromPHPImplicit
that returns a
Left
with an error message instead of throwing a run time exception.
Type classes
class ConversionFromPHPImplicitValueOrMismatch b whereSource
convFromPHPImplicitOM :: PHPSessionValue -> Either String bSource