note 102349 added to class.mongo

FaustoVanin@faustovanin
Newsgroups php.notes
Message-ID <[email protected]>
For those who are concerned on parsing JSON associative arrays from queries, this class could be useful. You just have to extend it and call parent constructor and it gets the job done.
It automatically initializes all your object attributes getting values from the array.

<?php

	#doc
	#	classname:	MongoClass
	#	scope:		PUBLIC
	#
	#/doc
	
	class MongoClass
	{
		#	internal variables
		protected $id;
		
		#	Constructor
		function __construct ($attList = array())
		{
			$reflection = new ReflectionObject($this);

			foreach ($attList as $attName => $attValue)
			{
				$attObj = $reflection->getProperty($attName);
				$attObj->setAccessible(true);
				$attObj->setValue($this, $attValue);
			}
		}
		###	
	
	}
	###
        class A extends MongoClass {
                private $name;
                private $value;
                private $weight;

                public function __construct($attList) {
                        parent::__construct($attList);
                }
        }

        $attList = array(
                "name" => "Beer",
                "value" => "Delicious",
                "weight" => 15.2
        ); //This is your JSON object associative aray

        $a = new A($attList);

?>
----
Server IP: 69.147.83.197
Probable Submitter: 187.58.245.104
----
Manual Page -- http://www.php.net/manual/en/class.mongo.php
Edit        -- https://master.php.net/note/edit/102349
Del: integrated  -- https://master.php.net/note/delete/102349/integrated
Del: useless     -- https://master.php.net/note/delete/102349/useless
Del: bad code    -- https://master.php.net/note/delete/102349/bad+code
Del: spam        -- https://master.php.net/note/delete/102349/spam
Del: non-english -- https://master.php.net/note/delete/102349/non-english
Del: in docs     -- https://master.php.net/note/delete/102349/in+docs
Del: other reasons-- https://master.php.net/note/delete/102349
Reject      -- https://master.php.net/note/reject/102349
Search      -- https://master.php.net/manage/user-notes.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.