note 112321 added to language.references.whatdo

From: Date: Sat, 01 Jun 2013 08:07:34 +0000
Subject: note 112321 added to language.references.whatdo
Groups: php.notes 
Request: Send a blank email to php-notes+get-195020@lists.php.net to get a copy of this message
About the example on array references. I think this should be written in the array chapter as well. Indeed if you are new to programming language in some way, you should beware that arrays are pointers to a vector of Byte(s). <?php $arr = array(1); ?> $arr here contains a reference to which the array is located. Writing : <?php echo $arr[0]; ?> dereferences the array to access its very first element. Now something that you should also be aware of (even you are not new to programming languages) is that PHP use references to contains the different values of an array. And that makes sense because the type of the elements of a PHP array can be different. Consider the following example : <?php $arr = array(1, 'test'); $point_to_test =& $arr[1]; $new_ref = 'new'; $arr[1] =& $new_ref; echo $arr[1]; // echo 'new'; echo $point_to_test; // echo 'test' ! (still pointed somewhere in the memory) ?> ---- Server IP: 69.147.83.199 Probable Submitter: 193.49.30.34 ---- Manual Page -- http://php.net/manual/en/language.references.whatdo.php Edit -- https://master.php.net/note/edit/112321 Del: integrated -- https://master.php.net/note/delete/112321/integrated Del: useless -- https://master.php.net/note/delete/112321/useless Del: bad code -- https://master.php.net/note/delete/112321/bad+code Del: spam -- https://master.php.net/note/delete/112321/spam Del: non-english -- https://master.php.net/note/delete/112321/non-english Del: in docs -- https://master.php.net/note/delete/112321/in+docs Del: other reasons-- https://master.php.net/note/delete/112321 Reject -- https://master.php.net/note/reject/112321 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#195020) next »