iFocus.Life News News - Breaking News & Top Stories - Latest World, US & Local News,Get the latest news, exclusives, sport, celebrities, showbiz, politics, business and lifestyle from The iFocus.Life,

How to Reference an Object's Name in PHP

104 64
    • 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.

      ?>

Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time
You might also like on "Technology"

Leave A Reply

Your email address will not be published.