Skip to main content
Added object and function information
Source Link
webdad3
  • 9.2k
  • 31
  • 131
  • 229

Using a very simple set of objects for this example in PHP.

Lets say:

ObjectA:

Properties: DescId;

Methods: getListofData();

ObjectB:

Properties: DescId;DescName;

Methods: getDescNameById();

What I want to know is what is the best way to get the DescName from ObjectB when ObjectA is the one calling the function from within a loop.

I'm thinking that I need to instantiate ObjectB (as New) and then pass in the ObjectA.DescId into the ObjectB.getDescNameById method.

For example:

class objectA {  function getListOfData(){  $myObjB= new objectB();   while ...   {   $myObjB->descId = $row["descId"];   $myDescName = $myObjB->getDescNameById();   ...   $i++;   }  } } 

I'm pretty sure the above will work but I'm not sure if it is the right way, or even if there are other ways of doing this. Is there a name for this type of thing? Some one mentioned Lazy Loading. Is that what this is in PHP?

Using a very simple set of objects for this example in PHP.

Lets say:

ObjectA:

Properties: DescId;

Methods: getListofData();

ObjectB:

Properties: DescId;DescName;

Methods: getDescNameById();

What I want to know is what is the best way to get the DescName from ObjectB when ObjectA is the one calling the function from within a loop.

I'm thinking that I need to instantiate ObjectB (as New) and then pass in the ObjectA.DescId into the ObjectB.getDescNameById method.

For example:

 $myObjB= new objectB(); while ... { $myObjB->descId = $row["descId"]; $myDescName = $myObjB->getDescNameById(); ... $i++; } 

I'm pretty sure the above will work but I'm not sure if it is the right way, or even if there are other ways of doing this. Is there a name for this type of thing? Some one mentioned Lazy Loading. Is that what this is in PHP?

Using a very simple set of objects for this example in PHP.

Lets say:

ObjectA:

Properties: DescId;

Methods: getListofData();

ObjectB:

Properties: DescId;DescName;

Methods: getDescNameById();

What I want to know is what is the best way to get the DescName from ObjectB when ObjectA is the one calling the function from within a loop.

I'm thinking that I need to instantiate ObjectB (as New) and then pass in the ObjectA.DescId into the ObjectB.getDescNameById method.

For example:

class objectA {  function getListOfData(){  $myObjB= new objectB();   while ...   {   $myObjB->descId = $row["descId"];   $myDescName = $myObjB->getDescNameById();   ...   $i++;   }  } } 

I'm pretty sure the above will work but I'm not sure if it is the right way, or even if there are other ways of doing this. Is there a name for this type of thing? Some one mentioned Lazy Loading. Is that what this is in PHP?

edited tags
Link
George Marian
  • 2.7k
  • 20
  • 21
Source Link
webdad3
  • 9.2k
  • 31
  • 131
  • 229

PHP Object question

Using a very simple set of objects for this example in PHP.

Lets say:

ObjectA:

Properties: DescId;

Methods: getListofData();

ObjectB:

Properties: DescId;DescName;

Methods: getDescNameById();

What I want to know is what is the best way to get the DescName from ObjectB when ObjectA is the one calling the function from within a loop.

I'm thinking that I need to instantiate ObjectB (as New) and then pass in the ObjectA.DescId into the ObjectB.getDescNameById method.

For example:

 $myObjB= new objectB(); while ... { $myObjB->descId = $row["descId"]; $myDescName = $myObjB->getDescNameById(); ... $i++; } 

I'm pretty sure the above will work but I'm not sure if it is the right way, or even if there are other ways of doing this. Is there a name for this type of thing? Some one mentioned Lazy Loading. Is that what this is in PHP?