PHP Classes

File: autoboxExampleClasses.php

Recommend this page to a friend!
  Classes of Artur Graniszewski   Java and C# compatible object autoboxing for PHP   autoboxExampleClasses.php   Download  
File: autoboxExampleClasses.php
Role: Class source
Content type: text/plain
Description: Example: Wrappers for the primitive PHP datatypes
Class: Java and C# compatible object autoboxing for PHP
Wrap string and integer values in objects
Author: By
Last change: Fixed phpdoc comments
Date: 13 years ago
Size: 3,003 bytes
 

Contents

Class file image Download
<?php

/**
 * JAVA Autoboxing (part of Lotos Framework)
 *
 * Copyright (c) 2005-2010 Artur Graniszewski (aargoth@boo.pl)
 * All rights reserved.
 *
 * @category Example
 * @package Lotos
 * @subpackage Examples
 * @copyright Copyright (c) 2005-2010 Artur Graniszewski (aargoth@boo.pl)
 * @license GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007
 * @version $Id$
 */

 
/**
 * Example class.
 *
 * Note: in order to use AutoBoxing, your class need to extend "AutoBoxedObject" class.
 */
class String extends AutoBoxedObject
{
    public
$value;
   
    public function
__construct($value) {
       
$this->value = $value;
    }
   
    public function
__toString() {
       
// NOTE: this must be a string, PHP forbids returning different type of variables in __toString() methods.
       
return "$this->value";
    }
   
    public function
toUpperCase() {
        return
strtoupper($this->value);
    }
}

/**
* Initializes a newly created String object.
* @return String created String object
*/
function & string($value = null) {
   
$x = & VariablesManager::getNewPointer(new String($value));
    return
$x;
}

/**
 * Example class.
 *
 * Note: in order to use AutoBoxing, your class need to extend "AutoBoxedObject" class.
 */
class CachedString extends AutoBoxedObject
{
    public
$value;
   
    public function
__construct($value) {
       
parent::__construct();
       
$this->value = & VariablesManager::getIntern($value, $this->internId);
    }
   
    public function
__destruct() {
       
VariablesManager::unsetIntern($this->internId);
       
parent::__destruct();
    }
   
    public function
__toString() {
       
// NOTE: this must be a string, PHP forbids returning different type of variables in __toString() methods.
       
return "$this->value";
    }
   
    public function
toUpperCase() {
        return
strtoupper($this->value);
    }
}

/**
* Initializes a newly created String object.
* @return String created String object
*/
function & cachedString($value = null) {
   
$x = & VariablesManager::getNewPointer(new CachedString($value));
    return
$x;
}

/**
 * Example class.
 *
 * Note: in order to use AutoBoxing, your class need to extend "AutoBoxedObject" class.
 */
class Integer extends AutoBoxedObject
{
    public
$value = 0;
   
    public function
__construct($value) {
       
$this->value = $value;
    }
   
    public function
__toString() {
       
// NOTE: this must be a string, PHP forbids returning different type of variables in __toString() methods.
       
return "{$this->value}";
    }
   
    public function
imStillAnObject() {
        return
true;
    }
}

/**
* Initializes a newly created Integer object.
* @return Integer created Integer object
*/
function & integer($value = null) {
   
$x = & VariablesManager::getNewPointer(new Integer($value));
    return
$x;
}