Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Joomla-Framework

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /joomla/base/object.php

Documentation is available at object.php

  1. <?php
  2. /**
  3.  * @version        $Id: object.php 6616 2007-02-14 00:22:01Z chrisdavenport $
  4.  * @package        Joomla.Framework
  5.  * @subpackage    Base
  6.  * @copyright    Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
  7.  * @license        GNU/GPL, see LICENSE.php
  8.  *  Joomla! is free software. This version may have been modified pursuant
  9.  *  to the GNU General Public License, and as distributed it includes or
  10.  *  is derivative of works licensed under the GNU General Public License or
  11.  *  other free or open source software licenses.
  12.  *  See COPYRIGHT.php for copyright notices and details.
  13.  */
  14.  
  15. /**
  16.  * Object class, allowing __construct in PHP4.
  17.  *
  18.  * @author        Johan Janssens <[email protected]>
  19.  * @package        Joomla.Framework
  20.  * @subpackage    Base
  21.  * @since        1.5
  22.  */
  23. class JObject
  24. {
  25.     /**
  26.      * A hack to support __construct() on PHP 4
  27.      * Hint: descendant classes have no PHP4 class_name() constructors,
  28.      * so this constructor gets called first and calls the top-layer __construct()
  29.      * which (if present) should call parent::__construct()
  30.      *
  31.      * @return Object 
  32.      */
  33.     function JObject()
  34.     {
  35.         $args func_get_args();
  36.         call_user_func_array(array(&$this'__construct')$args);
  37.     }
  38.  
  39.     /**
  40.      * Class constructor, overridden in descendant classes.
  41.      *
  42.      * @access    protected
  43.      */
  44.     function __construct({}
  45.  
  46.     /**
  47.      * Modifies a property of the object, creating it if it does not already exist.
  48.      *
  49.      * @param string $property The name of the property
  50.      * @param mixed  $value The value of the property to set
  51.       */
  52.     function set$property$value=null {
  53.         $this->$property $value;
  54.     }
  55.  
  56.     /**
  57.      * Returns a property of the object or the default value if the property is not set.
  58.      *
  59.      * @param string $property The name of the property
  60.      * @param mixed  $default The default value
  61.      * @return mixed The value of the property
  62.      * @see get(), getPublicProperties()
  63.       */
  64.     function get($property$default=null)
  65.     {
  66.         if(isset($this->$property)) {
  67.             return $this->$property;
  68.         }
  69.         return $default;
  70.     }
  71.  
  72.     /**
  73.      * Returns an array of public properties
  74.      *
  75.      * @param   boolean $assoc If true, returns an associative key=>value array
  76.      * @return  array 
  77.      * @see get(), toString()
  78.       */
  79.     function getPublicProperties$assoc false )
  80.     {
  81.         $vars array(array(),array());
  82.         foreach (get_object_vars$this as $key => $val)
  83.         {
  84.             if (substr$key0!= '_')
  85.             {
  86.                 $vars[0][$key;
  87.                 $vars[1][$key$val;
  88.             }
  89.         }
  90.         return $vars[$assoc 0];
  91.     }
  92.  
  93.     /**
  94.      * Object-to-string conversion.
  95.      * Each class can override it as necessary.
  96.      *
  97.      * @return string This name of this class
  98.      * @see get(), getPublicProperties()
  99.       */
  100.     function toString()
  101.     {
  102.         return get_class($this);
  103.     }
  104. }

Documentation generated on Mon, 05 Mar 2007 21:12:09 +0000 by phpDocumentor 1.3.1