Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a variable from another class PHP

Tags:

oop

php

I'm in the phase of learning OOP in PHP and i wanna know how to call a variable from another PHP class.

eg.

class first {
    public $var1 = 1;
}

I guess it's this way but i don't know how to continue:

$first = new $first();

like image 265
FBwall Avatar asked Nov 07 '11 09:11

FBwall


2 Answers

You should do something like this:

$first = new first();
echo $first->var1;
like image 70
xdazz Avatar answered Sep 23 '22 07:09

xdazz


You need to call it like this:

$first = new first();
$first->var1;
like image 32
Andrew Jackman Avatar answered Sep 25 '22 07:09

Andrew Jackman