Jump to content

Getting two properties from class


fluidsharp

Recommended Posts

Hello dear

Please give me advise. I'm learning class and didn't understand  how to get access to more then 1 properties of class. I'm using getter and setter method.

 

abstract class father
{
    protected $title; 
    protected $result;   
}
class connectDB extends father
{
    protected $select;
    protected $i;

   function setQuery($query)
     {
             //something code 
             //$resultFetch - is array, $i - quantity of iteration
          $this->select = $resultFetch;
          $this->i = $i;
    }

  function getQuery($select,$i)
    {
        return $this->select;
        return $this->i;                
    }
}

$db = new connectDB();
$sel = "SELECT * FROM......etc";
$db->setQuery($sel);
$get = $db->getQuery($selResult, $quantIter); //  <- how to get both "$select" and "$i"

 

I get value only from properties - "protected $select"  to $get,  but ($selResult, $quantIter) are = NULL

How to get both values together ???

Link to comment
https://forums.phpfreaks.com/topic/194236-getting-two-properties-from-class/
Share on other sites

You certainly can't go about it like that. Once you call return, a function (in this case method) is finished. The second return statement will never get ran. I can't really give any advice towards a solution, because I really don't understand what you are trying to do. If you need more than one item to come back from a getter in that manner, you will either have to pass the variables in as reference types rather than value types, or you will have to add all items you wish to return to an array and return the array.

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.