note 74658 added to function.json-decode

From: Date: Sun, 22 Apr 2007 16:15:52 +0000
Subject: note 74658 added to function.json-decode
Groups: php.notes 
Request: Send a blank email to php-notes+get-125766@lists.php.net to get a copy of this message
You can't transport Objects or serialize Classes, json_* replace it bei stdClass! <?php $dom = new DomDocument( '1.0', 'utf-8' ); $body = $dom->appendChild( $dom->createElement( "body" ) ); $body->appendChild( $dom->createElement( "forward", "Hallo" ) ); $JSON_STRING = json_encode( array( "aArray" => range( "a", "z" ), "bArray" => range( 1, 50 ), "cArray" => range( 1, 50, 5 ), "String" => "Value", "stdClass" => $dom, "XML" => $dom->saveXML() ) ); unset( $dom ); $Search = "XML"; $MyStdClass = json_decode( $JSON_STRING ); // var_dump( "<pre>" , $MyStdClass , "</pre>" ); try { throw new Exception( "$Search isn't a Instance of 'stdClass' Class by json_decode()." ); if ( $MyStdClass->$Search instanceof $MyStdClass ) var_dump( "<pre>instanceof:" , $MyStdClass->$Search , "</pre>" ); } catch( Exception $ErrorHandle ) { echo $ErrorHandle->getMessage(); if ( property_exists( $MyStdClass, $Search ) ) { $dom = new DomDocument( "1.0", "utf-8" ); $dom->loadXML( $MyStdClass->$Search ); $body = $dom->getElementsByTagName( "body" )->item(0); $body->appendChild( $dom->createElement( "rewind", "Nice" ) ); var_dump( htmlentities( $dom->saveXML(), ENT_QUOTES, 'utf-8' ) ); } } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 87.165.167.241 ---- Manual Page -- http://www.php.net/manual/en/function.json-decode.php Edit -- https://master.php.net/note/edit/74658 Del: integrated -- https://master.php.net/note/delete/74658/integrated Del: useless -- https://master.php.net/note/delete/74658/useless Del: bad code -- https://master.php.net/note/delete/74658/bad+code Del: spam -- https://master.php.net/note/delete/74658/spam Del: non-english -- https://master.php.net/note/delete/74658/non-english Del: in docs -- https://master.php.net/note/delete/74658/in+docs Del: other reasons-- https://master.php.net/note/delete/74658 Reject -- https://master.php.net/note/reject/74658 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#125766) next »