note 74658 deleted from function.json-decode by salathe

From: Date: Mon, 21 Sep 2020 15:00:29 +0000
Subject: note 74658 deleted from function.json-decode by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-215421@lists.php.net to get a copy of this message
Note Submitter: nospam (AT) hjcms (DOT) de ---- 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' ) ); } } ?>

« previous php.notes (#215421) next »