How to Reference an Object's Name in PHP
- 1). Decide how you will run your PHP code. If you have a PHP server, you can execute code using PHP files. If you do not have access to a PHP server, you can use an online PHP interpreter. Enter the code in the tutorial into either a PHP file or the online PHP interpreter.
- 2). Begin your PHP program with the following statement:
<?php - 3). Declare a new class that stores a single value. This can be done using the following code:
class ReferenceExample { public $dataType = 0;} - 4). Create a new instance of this class using the new operator, like this:
$i = new ReferenceExample; - 5). Create a reference to this new object using the & operator and store this reference in a variable named $r, like this:
$r = &$i; - 6). Print the value of the object using the reference, like this:
echo $r->dataType; - 7). Conclude your PHP program with the statement below. Your program is now ready to be tested on your PHP server or online PHP interpreter.
?>