note 100823 added to intro.spl-types

From: Date: Tue, 09 Nov 2010 13:04:43 +0000
Subject: note 100823 added to intro.spl-types
Groups: php.notes 
Request: Send a blank email to php-notes+get-173883@lists.php.net to get a copy of this message
@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) ---- Server IP: 69.147.83.197 Probable Submitter: 212.76.32.115 ---- Manual Page -- http://www.php.net/manual/en/intro.spl-types.php Edit -- https://master.php.net/note/edit/100823 Del: integrated -- https://master.php.net/note/delete/100823/integrated Del: useless -- https://master.php.net/note/delete/100823/useless Del: bad code -- https://master.php.net/note/delete/100823/bad+code Del: spam -- https://master.php.net/note/delete/100823/spam Del: non-english -- https://master.php.net/note/delete/100823/non-english Del: in docs -- https://master.php.net/note/delete/100823/in+docs Del: other reasons-- https://master.php.net/note/delete/100823 Reject -- https://master.php.net/note/reject/100823 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#173883) next »