The Additional function you have proposed seems like the easiest and best way to do it currently without changing the language. I was thinking of giving the cast syntax special meaning if used in connection with json_decode, but this would most likely be near to impossible.
Hi,
I like the general idea behind that proposal.
I'm not sure how you would want to implement that however (please
expand the rfc on that topic).
Do you want to give the cast syntax a special meaning if used in
connection with json_decode or add the general ability to
cast a stdClass object (as returned by json_decode) to a specific user
type or do you want to change json_decode to return a new class
(extending stdclass) that can be casted in the way you want? The first
two could be considered fundamental changes to the language, the third
may include serious bc concerns.
Wouldn't an additional function (maybe in addition to your proposed
interface; example: json_decode_to(string $json, string $className,
int $options)) solve the issue without changing the language?
Regards,
2015-07-13 15:22 GMT+02:00 Dean Eigenmann dean.eigenmann@icloud.com:
Ive just opened a new RFC https://wiki.php.net/rfc/jsonserializable
regarding Json to Object unserialization.
What about JsonDeserializable? I would like to have the choice to have a
serialize-only operation.
On Mon, Jul 13, 2015 at 10:13 AM, Dean Eigenmann dean.eigenmann@icloud.com
wrote:
The Additional function you have proposed seems like the easiest and best
way to do it currently without changing the language. I was thinking of
giving the cast syntax special meaning if used in connection with
json_decode, but this would most likely be near to impossible.On Jul 13, 2015, at 04:08 PM, "Sebastian B.-Hagensen" <
sbj.ml.read@gmail.com> wrote:Hi,
I like the general idea behind that proposal.
I'm not sure how you would want to implement that however (please
expand the rfc on that topic).
Do you want to give the cast syntax a special meaning if used in
connection with json_decode or add the general ability to
cast a stdClass object (as returned by json_decode) to a specific user
type or do you want to change json_decode to return a new class
(extending stdclass) that can be casted in the way you want? The first
two could be considered fundamental changes to the language, the third
may include serious bc concerns.Wouldn't an additional function (maybe in addition to your proposed
interface; example: json_decode_to(string $json, string $className,
int $options)) solve the issue without changing the language?Regards,
2015-07-13 15:22 GMT+02:00 Dean Eigenmann dean.eigenmann@icloud.com:
Ive just opened a new RFC https://wiki.php.net/rfc/jsonserializable
regarding Json to Object unserialization.
--
Guilherme Blanco
MSN: guilhermeblanco@hotmail.com
GTalk: guilhermeblanco
Toronto - ON/Canada
guilhermeblanco@gmail.com wrote on 13/07/2015 15:19:
What about JsonDeserializable? I would like to have the choice to have a
serialize-only operation.
Yeah, this would need to be a new interface, because interfaces can't
have optional methods, so changing the existing interface would
instantly break all existing implementations, which would be a big no-no
IMHO.
I will update the spec for it to be a function, called something like json_decode_to($json, $class, $mapping = []);
With mapping you could then specify with array keys map to which class property.
Sent from my iPhone
guilhermeblanco@gmail.com wrote on 13/07/2015 15:19:
What about JsonDeserializable? I would like to have the choice to have a
serialize-only operation.Yeah, this would need to be a new interface, because interfaces can't have optional methods, so changing the existing interface would instantly break all existing implementations, which would be a big no-no IMHO.