Jump to content

Unable to carry avriable from one class to other


bapi

Recommended Posts

Hi,

 

I am new to OOP and got the bitter tast right now.

 

i created two class let name be class A and Class B.

 

Class B - has a method with variable

 

class B{

        function something($var1, Var2)

        {

              ...............

        }

}

 

Now i used this class in class A

 

class A{

 

        function nextthing(){

              A::something($var1, Var2)

              .....................................

          }

}

 

 

Now i get error message "Undifine $var1 & $var2" when i run it thru other file,

 

How can i solve this problem.

maby in your parent class use a accessor method ie (set and get method) to set your data members. and then extend the parent class with a subclass. and access them through the subclass which would extend the patent class through inheritance.

 

now you could set up a constructor in you parent class to set your data members OR just invoke your methods to set them so they can be accessed.

 

failing that maby read up on OOP more in depth

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.