3v4l.org

run code in 300+ PHP versions simultaneously
<?php class myClass { public $item1 = 1; public $item2 = '中文'; function to_json() { //url编码,避免json_encode将中文转为unicode $this->item2 = urlencode($this->item2); $str_json = json_encode($this); //url解码,转完json后将各属性返回,确保对象属性不变 $this->item2 = urldecode($this->item2); return urldecode($str_json); } } $c = new myClass(); echo json_encode($c); echo '<br/>'; echo $c->to_json(); echo '<br/>'; echo json_encode($c); echo '<br/>'; echo json_encode('胥');
Output for git.master, git.master_jit, rfc.property-hooks
{"item1":1,"item2":"\u4e2d\u6587"}<br/>{"item1":1,"item2":"中文"}<br/>{"item1":1,"item2":"\u4e2d\u6587"}<br/>"\u80e5"

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
36.75 ms | 401 KiB | 8 Q