From: leonardo at ebussola dot com
Operating system: all
PHP version: Irrelevant
Package: JSON related
Bug Type: Feature/Change Request
Bug description:json_encode could consider __get magic method
Description:
------------
When I use json_encode on a class, this get the properties values
directly and bypass the __get magic method.
It would be great if I could control the properties with __get
Test script:
---------------
class Example {
public foo;
public function __construct() {
$this->foo = 'bar;
}
public function __get($param) {
return $this->$param . ' modified';
}
}
$foo = new Example();
echo json_encode($foo);
Expected result:
----------------
{"foo":"bar modified"}
Actual result:
--------------
{"foo":"bar"}
--
Edit bug report at https://bugs.php.net/bug.php?id=65858&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=65858&r=trysnapshot54
Try a snapshot (PHP 5.5):
https://bugs.php.net/fix.php?id=65858&r=trysnapshot55
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=65858&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=65858&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=65858&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=65858&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=65858&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=65858&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=65858&r=support
Expected behavior: https://bugs.php.net/fix.php?id=65858&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=65858&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=65858&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=65858&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65858&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=65858&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=65858&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=65858&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=65858&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=65858&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=65858&r=mysqlcfg
Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!
Check out: eBank.nz (Art Generator) |
Netwrck.com (AI Tools) |
Text-Generator.io (AI API) |
BitBank.nz (Crypto AI) |
ReadingTime (Kids Reading) |
RewordGame |
BigMultiplayerChess |
WebFiddle |
How.nz |
Helix AI Assistant