2

I'm trying to pass an array to a class constructor, and for some reason the constructor receives different arrays than the ones I'm sending. The code building the 2 arrays and sending them:

$exportArray=array();
            foreach($new->arr as $ar){
                $values[]=intval($ar[4]);
                $dates[]=strtotime($ar[1]);
                $exportArray[]=array($ar[5],$ar[0],$ar[2],$ar[3],$ar[1]);
            }
            $new->query="SELECT distinct c_name,date,m_name,t_amount,t_id FROM transport,customer,driver,material WHERE"
                    . " customer.c_id=transport.c_id AND material.m_id=transport.m_id AND transport.d_id=$name ORDER BY date DESC LIMIT $lim";
            //var_dump($new->query);
            $new->again();
            foreach($new->arr as $ar){
                echo "<tr><td><a href='customers.php?c_name=$ar[0]'>$ar[0]</a></td><td>$ar[1]</td><td><a href='materials.php?m_name=$ar[2]'>$ar[2]</a></td><td>$ar[3]</tr>";
                //var_dump($ar);
            }
            ?>
        </table>
  <?php
    if(isset($lim)&&$lim!="1"){
        $qr=new query("SELECT last FROM graph");
        $last=$qr->arr[0][0];
            var_dump($values);
            var_dump($dates);
        $graph1=new graphs($dates,$values,"Deliveries With Respect To Dates","driver");
        $graph1->getGraph("date");
        $qr->again();

The class constructor receives them and performs checks:

class graphs{

    public $xtype=NULL;
    public $ytype=NULL;
    public $graph=NULL;
    private $xs=array();
    private $ys=array();
    public $type=NULL;

    public function __construct($arr1,$arr2,$title,$type){
        if(!is_array($arr1)||!is_array($arr2)){
            die("in order to see the graph, you need more than one result!");
        }
        elseif(count($arr1)<=1||count($arr2)<=1){
            var_dump($arr1);
            var_dump($arr2);
            die("in order to see the RELEVANT graph, you need more than one result!");
        }
        $this->title=$title;
        $this->xs=$arr1;
        $this->ys=$arr2;
        $this->graph= new Graph(600,400,'auto');
        $this->graph->SetScale("textlin");
        $this->graph->SetShadow();
        $this->graph->title->Set($this->title);
        $this->graph->title->SetFont(FF_ARIAL,FS_NORMAL,9);
        $this->graph->xaxis->setTickLabels($arr1);
        if($type=="driver"){
            $this->type=1;
        }
        elseif($type=="customer"){
            $this->type=2;
        }
        elseif($type=="material"){
            $this->type=3;
        }
    }//construct

Getting this on browser(first 2 dumps are what i'm sending,second ones are the ones the class is dumping):

enter image description here

5
  • 1
    Please show us the full script with class definition and everything Commented Jan 17, 2015 at 15:57
  • I can't replicate that - are you certain that code gives you that error? Because according to the error, you're somehow getting the string customers, which isn't present in your input data at all. phpfiddle.org/main/code/szvx-6byt Commented Jan 17, 2015 at 15:58
  • Added more code info Commented Jan 17, 2015 at 16:06
  • What is the output if you use print_r() right at the top of the constructor? (Also comment all other code lines out) Commented Jan 17, 2015 at 16:08
  • print_r() right after constructor declaration gives the right info. Commented Jan 17, 2015 at 16:12

1 Answer 1

1

I think some of your initializations inside your constructor, especially for your $arr1 & $arr2 argument

   $this->.. = $arr1;
   $this->.. = $arr2 ;

Should be declared before your if(!is_array($arr1)||!is_array($arr2)){..

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.