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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.