PHP 8.5.0 Alpha 4 available for testing

Voting

: three minus three?
(Example: nine)

The Note You're Voting On

admin at torntech dot com
11 years ago
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;
//ouputs: 5,5

echo ' | ';

$b = 6;
echo
$a . ',' . $b;
//outputs: 6,6

echo ' | ';
unset(
$a );
echo
$a . ', ' . $b;

//outputs: , 6

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();
//outputs 1, 1
$Product->id = 2;
echo
' | ';
echo
$Product->id . ', ' . $Product->getProductId();
//outputs 2, 2
$Product->id = null;
echo
' | ';
echo
$Product->id . ', ' . $Product->getProductId();
//outouts ,

<< Back to user notes page

To Top