WebRef.eu  - Internet Marketing and Online Business Resources

Home | Contact Us

Google
 

Back to PHP Scripts

How to Access a PHP Class Variable from Outside the Class

The below script demonstrates how to access a PHP class variable from outside the class:

<?php
//PHP class starts
//We've put this class within the page but could have put it in a separate file


class myClass {

//variable will be global inside the object
//the variable can be accessed both inside and outside of the class as we will see below


//In PHP5 you declare a variable using public if you want it to be accessible outside the class

public $my_var = 'testing';

function myFunctionName(){
//this function is empty at the moment
}
}
//PHP class ends

//create an instance of the class as the $mine object

$mine=new myClass();

//You access a class variable from outside the class using the arrow operator. The arrow tells php that the variable is part of the $mine object

echo $mine->my_var;
?>

Back to PHP Scripts

 



Join Top Affiliate Networks Join Top Affiliate Networks >>>



Paid On Results








Home | Contact Us

All Content ©2006 WebRef.eu