note 100823 deleted from intro.spl-types by danbrown
| From: | danbrown@php.net | Date: | Tue, 09 Nov 2010 17:03:27 +0000 |
| Subject: | note 100823 deleted from intro.spl-types by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-173889@lists.php.net to get a copy of this message | ||
Note Submitter: Artur Graniszewski
----
@tom please note, that from this moment you can use simulated datatype autoboxing/unboxing provided
by this dedicated PHP class called 'Java and C# compatible object autoboxing in PHP':
http://www.phpclasses.org/package/6570-PHP-Wrap-string-and-integer
As it name suggests this class works similar to Java or C# autoboxing, what's more it
additionaly provides strong data type enforcing and allows you to do some basic mathematical
operations on the PHP objects.
Basic example taken from the examples file:
<?php
// load required library
include("./variablesManager.php");
// and an example classes
include("./autoboxExampleClasses.php");
// create a new String object (see autoboxExampleClass.php for class definition)
$text = & string("Initial text");
echo 'The initial value of $text variable is "'.$text.'"<br />';
echo 'The initial datatype of $text variable is '.gettype($text).(is_object($text) ?
' ('.get_class($text).')': '').'<br />';
// ------------------------
echo "<hr />";
echo 'Now we are changing $text value to 12 (integer)<br />';
// now try to change the data type to PHP Integer:
$text = 12;
// from this moment $text should be an integer and not a String object (this is a default PHP
behaviour),
// but thanks to our autoboxing, this isn't true. $text is still an object
echo 'The new value of $text variable is "'.$text.'"<br />';
echo 'The new datatype of $text variable is '.gettype($text).(is_object($text) ? '
('.get_class($text).')': '').'<br />';
?>
outputs:
The initial value of $text variable is "Initial text"
The initial datatype of $text variable is object (String)
------------------------
Now we are changing $text value to 12 (integer)
The new value of $text variable is "12"
The new datatype of $text variable is object (String)