Something that has not been discussed so far is reference of a reference.
I needed a quick and dirty method of aliasing incorrect naming until a proper rewrite could be done.
Hope this saves someone else the time of testing since it was not covered in the Does/Are/Are Not pages.
Far from best practice, but it worked.
<?php
$a = 0;
$b =& $a;
$a =& $b;
$a = 5;
echo $a . ', ' . $b;
echo ' | ';
$b = 6;
echo $a . ',' . $b;
echo ' | ';
unset( $a );
echo $a . ', ' . $b;
class Product {
public $id;
private $productid;
public function __construct( $id = null ) {
$this->id =& $this->productid;
$this->productid =& $this->id;
$this->id = $id;
}
public function getProductId() {
return $this->productid;
}
}
echo ' | ';
$Product = new Product( 1 );
echo $Product->id . ', ' . $Product->getProductId();
$Product->id = 2;
echo ' | ';
echo $Product->id . ', ' . $Product->getProductId();
$Product->id = null;
echo ' | ';
echo $Product->id . ', ' . $Product->getProductId();