JavaEar 专注于收集分享传播有价值的技术资料

Cannot access empty property error

问题描述


英文原文

I'm working on an advanced search but got error

Fatal error: Cannot access empty property *$this->$Personnummer*

Here is my controller:

<?php
include 'c:/wamp/www/mvc/model/SearchProcessor.php';
// if the user clicks the submit button, it sends its name values here and if not empty, binds them to $data.
        if(isset($_POST['button'])) {

                if($_POST['name'] !='');
                {
                        $data['name'] = $_POST['name'];
                }

                if($_POST['lastname'] !='');
                {
                        $data['lastname'] = $_POST['lastname'];
                }


                if($_POST['Personnummer_search'] !='');
                {
                        $data['Personnummer'] = $_POST['Personnummer_search'];
                }

                if($_POST['Kon_search'] !='');
                {
                        $data['Kon_search'] = $_POST['Kon_search'];
                }

                if($_POST['Anvands_search'] !='');
                {
                        $data['Anvands_search'] = $_POST['Anvands_search'];
                }

                if($_POST['Lan_search'] !='');
                {
                        $data['Lan_search'] = $_POST['Lan_search'];
                }

                if($_POST['Processormodell_search'] !='');
                {
                        $data['Processormodell_search'] = $_POST['Processormodell_search'];
                }

                if($_POST['Sida_search'] !='');
                {
                        $data['Sida_search'] = $_POST['Sida_search'];
                }

                if($_POST['utlamnat_search'] !='');
                {
                        $data['utlamnat_search'] = $_POST['utlamnat_search'];
                }

                if($_POST['ProcessorSerie_search'] !='');
                {
                        $data['ProcessorSerie_search'] = $_POST['ProcessorSerie_search'];
                }

                if($_POST['Tillverkare_search'] !='');
                {
                        $data['Tillverkare_search'] = $_POST['Tillverkare_search'];
                }


                $displayResults = new SearchProcessor($db,$data);
                $Results = $displayResults->getSearchResult();

Here is the model:

<?php
require_once 'Database.php';
//This class is for searching for patient and their processors
class SearchProcessor extends Database {
    private $Personnummer;
    private $TheKon;
    private $TheLan;
    private $name;
    private $TheLastname;
    private $TheProcessor;
    private $TheAnvands;
    private $TheSida;
    private $TheUtlamnat;
    private $TheSerienummer;
    private $TheTillverkare;

    //The constructor of both the parent and child class
    function __construct(mysqli $db, $data)
    {
        parent::__construct($db);
        //set data
        $this->setData($data);
        // get search result
        $this->getSearchResult();
    }
    //Sets the data
    function setData($data)
    {
        $this->name = $data['name'];
        $this->TheLastname = $data['lastname'];
        $this->Personnummer = $data['Personnummer'];
        $this->TheKon = $data['Kon_search'];
        $this->TheAnvands = $data['Anvands_search'];
        $this->TheLan = $data['Lan_search'];
        $this->TheProcessor = $data['Processormodell_search'];
        $this->TheSida =$data['Sida_search'];
        $this->TheUtlamnat =$data['utlamnat_search'];
        $this->TheSerienummer = $data['ProcessorSerie_search'];
        $this->TheTillverkare = $data['Tillverkare_search'];

    }


//This function searches each column regarding patient and its processors.
    function getSearchResult() {

        $where = array();
            $where[] =  "Patient.Patient LIKE '%".$this->$Personnummer."%'"; //<--- ERROR  Cannot access empty property 
            $where[] =  "person.Namn LIKE '%".$this->name."%'";
            $where[] =  "person.Efternamn LIKE '%".$this->TheLastname."%'";
            $where[] =  "person.Kon LIKE '%".$this->TheKon."%'";
            $where[] =  "processorpatient.Sida LIKE '%".$this->TheSida."%'";
            $where[] =  "person.Lan LIKE '%".$this->TheLan."%'";
            $where[] =  "processorpatient.Tillverkare LIKE '%".$this->TheTillverkare."%'";
            $where[] =  "processorpatient.Processor LIKE '%".$this->TheProcessor."%'";
            $where[] =  "processorpatient.Utlamnat LIKE '%".$this->TheUtlamnat."%'";
            $where[] =  "processorpatient.Anvands LIKE '%".$this->TheAnvands."%'";
            $where[] =  "processorpatient.Serienummer LIKE '%".$this->TheSerienummer."%'";

        if(count($where)) // here it counts the amount of $where and a extends the query to search deeper into the database.
        {

            $Data = array();
            $sql = "Select * from patient left join person on person.Personnummer = patient.Patient left join processorpatient on processorpatient.patientv = patient.Patient
     WHERE ".implode(" AND ",$where);
            if(!$result = $this->mysqli->query($sql)) {
                throw new exception("Error: Can not execute the query.");
            } else {
                $Count = $result->num_rows;
                if($Count>0)
                {
                    for($i=0; $i<$Count; $i++)
                    {
                        $Data[$i] = $result->fetch_assoc();
                    }
                }
            }
            return $Data;
    }

    }

}

What I want to be doing is assign user input $_POST[''] to variables $data[''] in the controller. And then pass it the model class that is supposed to bind it with their own private variables in which is giving value to the query. But I'm getting error Cannot access empty property $this->$Personnummer at the model


中文翻译

I'm working on an advanced search but got error

Fatal error: Cannot access empty property *$this->$Personnummer*

Here is my controller:

<?php
include 'c:/wamp/www/mvc/model/SearchProcessor.php';
// if the user clicks the submit button, it sends its name values here and if not empty, binds them to $data.
        if(isset($_POST['button'])) {

                if($_POST['name'] !='');
                {
                        $data['name'] = $_POST['name'];
                }

                if($_POST['lastname'] !='');
                {
                        $data['lastname'] = $_POST['lastname'];
                }


                if($_POST['Personnummer_search'] !='');
                {
                        $data['Personnummer'] = $_POST['Personnummer_search'];
                }

                if($_POST['Kon_search'] !='');
                {
                        $data['Kon_search'] = $_POST['Kon_search'];
                }

                if($_POST['Anvands_search'] !='');
                {
                        $data['Anvands_search'] = $_POST['Anvands_search'];
                }

                if($_POST['Lan_search'] !='');
                {
                        $data['Lan_search'] = $_POST['Lan_search'];
                }

                if($_POST['Processormodell_search'] !='');
                {
                        $data['Processormodell_search'] = $_POST['Processormodell_search'];
                }

                if($_POST['Sida_search'] !='');
                {
                        $data['Sida_search'] = $_POST['Sida_search'];
                }

                if($_POST['utlamnat_search'] !='');
                {
                        $data['utlamnat_search'] = $_POST['utlamnat_search'];
                }

                if($_POST['ProcessorSerie_search'] !='');
                {
                        $data['ProcessorSerie_search'] = $_POST['ProcessorSerie_search'];
                }

                if($_POST['Tillverkare_search'] !='');
                {
                        $data['Tillverkare_search'] = $_POST['Tillverkare_search'];
                }


                $displayResults = new SearchProcessor($db,$data);
                $Results = $displayResults->getSearchResult();

Here is the model:

<?php
require_once 'Database.php';
//This class is for searching for patient and their processors
class SearchProcessor extends Database {
    private $Personnummer;
    private $TheKon;
    private $TheLan;
    private $name;
    private $TheLastname;
    private $TheProcessor;
    private $TheAnvands;
    private $TheSida;
    private $TheUtlamnat;
    private $TheSerienummer;
    private $TheTillverkare;

    //The constructor of both the parent and child class
    function __construct(mysqli $db, $data)
    {
        parent::__construct($db);
        //set data
        $this->setData($data);
        // get search result
        $this->getSearchResult();
    }
    //Sets the data
    function setData($data)
    {
        $this->name = $data['name'];
        $this->TheLastname = $data['lastname'];
        $this->Personnummer = $data['Personnummer'];
        $this->TheKon = $data['Kon_search'];
        $this->TheAnvands = $data['Anvands_search'];
        $this->TheLan = $data['Lan_search'];
        $this->TheProcessor = $data['Processormodell_search'];
        $this->TheSida =$data['Sida_search'];
        $this->TheUtlamnat =$data['utlamnat_search'];
        $this->TheSerienummer = $data['ProcessorSerie_search'];
        $this->TheTillverkare = $data['Tillverkare_search'];

    }


//This function searches each column regarding patient and its processors.
    function getSearchResult() {

        $where = array();
            $where[] =  "Patient.Patient LIKE '%".$this->$Personnummer."%'"; //<--- ERROR  Cannot access empty property 
            $where[] =  "person.Namn LIKE '%".$this->name."%'";
            $where[] =  "person.Efternamn LIKE '%".$this->TheLastname."%'";
            $where[] =  "person.Kon LIKE '%".$this->TheKon."%'";
            $where[] =  "processorpatient.Sida LIKE '%".$this->TheSida."%'";
            $where[] =  "person.Lan LIKE '%".$this->TheLan."%'";
            $where[] =  "processorpatient.Tillverkare LIKE '%".$this->TheTillverkare."%'";
            $where[] =  "processorpatient.Processor LIKE '%".$this->TheProcessor."%'";
            $where[] =  "processorpatient.Utlamnat LIKE '%".$this->TheUtlamnat."%'";
            $where[] =  "processorpatient.Anvands LIKE '%".$this->TheAnvands."%'";
            $where[] =  "processorpatient.Serienummer LIKE '%".$this->TheSerienummer."%'";

        if(count($where)) // here it counts the amount of $where and a extends the query to search deeper into the database.
        {

            $Data = array();
            $sql = "Select * from patient left join person on person.Personnummer = patient.Patient left join processorpatient on processorpatient.patientv = patient.Patient
     WHERE ".implode(" AND ",$where);
            if(!$result = $this->mysqli->query($sql)) {
                throw new exception("Error: Can not execute the query.");
            } else {
                $Count = $result->num_rows;
                if($Count>0)
                {
                    for($i=0; $i<$Count; $i++)
                    {
                        $Data[$i] = $result->fetch_assoc();
                    }
                }
            }
            return $Data;
    }

    }

}

What I want to be doing is assign user input $_POST[''] to variables $data[''] in the controller. And then pass it the model class that is supposed to bind it with their own private variables in which is giving value to the query. But I'm getting error Cannot access empty property $this->$Personnummer at the model

I'm working on an advanced search but got error

Fatal error: Cannot access empty property *$this->$Personnummer*

Here is my controller:

<?php
include 'c:/wamp/www/mvc/model/SearchProcessor.php';
// if the user clicks the submit button, it sends its name values here and if not empty, binds them to $data.
        if(isset($_POST['button'])) {

                if($_POST['name'] !='');
                {
                        $data['name'] = $_POST['name'];
                }

                if($_POST['lastname'] !='');
                {
                        $data['lastname'] = $_POST['lastname'];
                }


                if($_POST['Personnummer_search'] !='');
                {
                        $data['Personnummer'] = $_POST['Personnummer_search'];
                }

                if($_POST['Kon_search'] !='');
                {
                        $data['Kon_search'] = $_POST['Kon_search'];
                }

                if($_POST['Anvands_search'] !='');
                {
                        $data['Anvands_search'] = $_POST['Anvands_search'];
                }

                if($_POST['Lan_search'] !='');
                {
                        $data['Lan_search'] = $_POST['Lan_search'];
                }

                if($_POST['Processormodell_search'] !='');
                {
                        $data['Processormodell_search'] = $_POST['Processormodell_search'];
                }

                if($_POST['Sida_search'] !='');
                {
                        $data['Sida_search'] = $_POST['Sida_search'];
                }

                if($_POST['utlamnat_search'] !='');
                {
                        $data['utlamnat_search'] = $_POST['utlamnat_search'];
                }

                if($_POST['ProcessorSerie_search'] !='');
                {
                        $data['ProcessorSerie_search'] = $_POST['ProcessorSerie_search'];
                }

                if($_POST['Tillverkare_search'] !='');
                {
                        $data['Tillverkare_search'] = $_POST['Tillverkare_search'];
                }


                $displayResults = new SearchProcessor($db,$data);
                $Results = $displayResults->getSearchResult();

Here is the model:

<?php
require_once 'Database.php';
//This class is for searching for patient and their processors
class SearchProcessor extends Database {
    private $Personnummer;
    private $TheKon;
    private $TheLan;
    private $name;
    private $TheLastname;
    private $TheProcessor;
    private $TheAnvands;
    private $TheSida;
    private $TheUtlamnat;
    private $TheSerienummer;
    private $TheTillverkare;

    //The constructor of both the parent and child class
    function __construct(mysqli $db, $data)
    {
        parent::__construct($db);
        //set data
        $this->setData($data);
        // get search result
        $this->getSearchResult();
    }
    //Sets the data
    function setData($data)
    {
        $this->name = $data['name'];
        $this->TheLastname = $data['lastname'];
        $this->Personnummer = $data['Personnummer'];
        $this->TheKon = $data['Kon_search'];
        $this->TheAnvands = $data['Anvands_search'];
        $this->TheLan = $data['Lan_search'];
        $this->TheProcessor = $data['Processormodell_search'];
        $this->TheSida =$data['Sida_search'];
        $this->TheUtlamnat =$data['utlamnat_search'];
        $this->TheSerienummer = $data['ProcessorSerie_search'];
        $this->TheTillverkare = $data['Tillverkare_search'];

    }


//This function searches each column regarding patient and its processors.
    function getSearchResult() {

        $where = array();
            $where[] =  "Patient.Patient LIKE '%".$this->$Personnummer."%'"; //<--- ERROR  Cannot access empty property 
            $where[] =  "person.Namn LIKE '%".$this->name."%'";
            $where[] =  "person.Efternamn LIKE '%".$this->TheLastname."%'";
            $where[] =  "person.Kon LIKE '%".$this->TheKon."%'";
            $where[] =  "processorpatient.Sida LIKE '%".$this->TheSida."%'";
            $where[] =  "person.Lan LIKE '%".$this->TheLan."%'";
            $where[] =  "processorpatient.Tillverkare LIKE '%".$this->TheTillverkare."%'";
            $where[] =  "processorpatient.Processor LIKE '%".$this->TheProcessor."%'";
            $where[] =  "processorpatient.Utlamnat LIKE '%".$this->TheUtlamnat."%'";
            $where[] =  "processorpatient.Anvands LIKE '%".$this->TheAnvands."%'";
            $where[] =  "processorpatient.Serienummer LIKE '%".$this->TheSerienummer."%'";

        if(count($where)) // here it counts the amount of $where and a extends the query to search deeper into the database.
        {

            $Data = array();
            $sql = "Select * from patient left join person on person.Personnummer = patient.Patient left join processorpatient on processorpatient.patientv = patient.Patient
     WHERE ".implode(" AND ",$where);
            if(!$result = $this->mysqli->query($sql)) {
                throw new exception("Error: Can not execute the query.");
            } else {
                $Count = $result->num_rows;
                if($Count>0)
                {
                    for($i=0; $i<$Count; $i++)
                    {
                        $Data[$i] = $result->fetch_assoc();
                    }
                }
            }
            return $Data;
    }

    }

}

What I want to be doing is assign user input $_POST[''] to variables $data[''] in the controller. And then pass it the model class that is supposed to bind it with their own private variables in which is giving value to the query. But I'm getting error Cannot access empty property $this->$Personnummer at the model

I'm working on an advanced search but got error

Fatal error: Cannot access empty property *$this->$Personnummer*

Here is my controller:

<?php
include 'c:/wamp/www/mvc/model/SearchProcessor.php';
// if the user clicks the submit button, it sends its name values here and if not empty, binds them to $data.
        if(isset($_POST['button'])) {

                if($_POST['name'] !='');
                {
                        $data['name'] = $_POST['name'];
                }

                if($_POST['lastname'] !='');
                {
                        $data['lastname'] = $_POST['lastname'];
                }


                if($_POST['Personnummer_search'] !='');
                {
                        $data['Personnummer'] = $_POST['Personnummer_search'];
                }

                if($_POST['Kon_search'] !='');
                {
                        $data['Kon_search'] = $_POST['Kon_search'];
                }

                if($_POST['Anvands_search'] !='');
                {
                        $data['Anvands_search'] = $_POST['Anvands_search'];
                }

                if($_POST['Lan_search'] !='');
                {
                        $data['Lan_search'] = $_POST['Lan_search'];
                }

                if($_POST['Processormodell_search'] !='');
                {
                        $data['Processormodell_search'] = $_POST['Processormodell_search'];
                }

                if($_POST['Sida_search'] !='');
                {
                        $data['Sida_search'] = $_POST['Sida_search'];
                }

                if($_POST['utlamnat_search'] !='');
                {
                        $data['utlamnat_search'] = $_POST['utlamnat_search'];
                }

                if($_POST['ProcessorSerie_search'] !='');
                {
                        $data['ProcessorSerie_search'] = $_POST['ProcessorSerie_search'];
                }

                if($_POST['Tillverkare_search'] !='');
                {
                        $data['Tillverkare_search'] = $_POST['Tillverkare_search'];
                }


                $displayResults = new SearchProcessor($db,$data);
                $Results = $displayResults->getSearchResult();

Here is the model:

<?php
require_once 'Database.php';
//This class is for searching for patient and their processors
class SearchProcessor extends Database {
    private $Personnummer;
    private $TheKon;
    private $TheLan;
    private $name;
    private $TheLastname;
    private $TheProcessor;
    private $TheAnvands;
    private $TheSida;
    private $TheUtlamnat;
    private $TheSerienummer;
    private $TheTillverkare;

    //The constructor of both the parent and child class
    function __construct(mysqli $db, $data)
    {
        parent::__construct($db);
        //set data
        $this->setData($data);
        // get search result
        $this->getSearchResult();
    }
    //Sets the data
    function setData($data)
    {
        $this->name = $data['name'];
        $this->TheLastname = $data['lastname'];
        $this->Personnummer = $data['Personnummer'];
        $this->TheKon = $data['Kon_search'];
        $this->TheAnvands = $data['Anvands_search'];
        $this->TheLan = $data['Lan_search'];
        $this->TheProcessor = $data['Processormodell_search'];
        $this->TheSida =$data['Sida_search'];
        $this->TheUtlamnat =$data['utlamnat_search'];
        $this->TheSerienummer = $data['ProcessorSerie_search'];
        $this->TheTillverkare = $data['Tillverkare_search'];

    }


//This function searches each column regarding patient and its processors.
    function getSearchResult() {

        $where = array();
            $where[] =  "Patient.Patient LIKE '%".$this->$Personnummer."%'"; //<--- ERROR  Cannot access empty property 
            $where[] =  "person.Namn LIKE '%".$this->name."%'";
            $where[] =  "person.Efternamn LIKE '%".$this->TheLastname."%'";
            $where[] =  "person.Kon LIKE '%".$this->TheKon."%'";
            $where[] =  "processorpatient.Sida LIKE '%".$this->TheSida."%'";
            $where[] =  "person.Lan LIKE '%".$this->TheLan."%'";
            $where[] =  "processorpatient.Tillverkare LIKE '%".$this->TheTillverkare."%'";
            $where[] =  "processorpatient.Processor LIKE '%".$this->TheProcessor."%'";
            $where[] =  "processorpatient.Utlamnat LIKE '%".$this->TheUtlamnat."%'";
            $where[] =  "processorpatient.Anvands LIKE '%".$this->TheAnvands."%'";
            $where[] =  "processorpatient.Serienummer LIKE '%".$this->TheSerienummer."%'";

        if(count($where)) // here it counts the amount of $where and a extends the query to search deeper into the database.
        {

            $Data = array();
            $sql = "Select * from patient left join person on person.Personnummer = patient.Patient left join processorpatient on processorpatient.patientv = patient.Patient
     WHERE ".implode(" AND ",$where);
            if(!$result = $this->mysqli->query($sql)) {
                throw new exception("Error: Can not execute the query.");
            } else {
                $Count = $result->num_rows;
                if($Count>0)
                {
                    for($i=0; $i<$Count; $i++)
                    {
                        $Data[$i] = $result->fetch_assoc();
                    }
                }
            }
            return $Data;
    }

    }

}

What I want to be doing is assign user input $_POST[''] to variables $data[''] in the controller. And then pass it the model class that is supposed to bind it with their own private variables in which is giving value to the query. But I'm getting error Cannot access empty property $this->$Personnummer at the model

1个回答

    最佳答案

  1. 英文原文

    access variable without $ as like same as you defined above

    $this->Personnummer = $data['Personnummer'];
    

    so access this like

    $where[] =  "Patient.Patient LIKE '%".$this->Personnummer."%'";
    

    中文翻译

    access variable without $ as like same as you defined above

    $this->Personnummer = $data['Personnummer'];
    

    so access this like

    $where[] =  "Patient.Patient LIKE '%".$this->Personnummer."%'";