There is such code:

var $createdatabase = 'CREATE DATABASE IF NOT EXISTS '.$this->sql_database; 

$ this-> sql_database - a variable inherited from a child class. Swears at the point. If you put quotes:

 var $createdatabase = "CREATE DATABASE IF NOT EXISTS $this->sql_database"; 

Begins to swear at the first quote, what's wrong?

    3 answers 3

    So no one gave the right answer:

    1. Do you write in PHP4? Not? So why are you using the obsolete keyword var, and not protected, public, private?
    2. Variable declarations cannot use constructed values. For this, a constructor function is usually used.
    3. I advise you to use additional functions mysql_real_escape_string, etc. when adding parameters.

    PS I give you a deuce for knowing PHP.

      Well, right swears. The parent should not see anything in the child class. To remove the error, you must define the variable sql_database in the parent class, but changing the value in the child class will not change the value of the variable in the parent class.

      • Why should I declare it if it is already declared and initialized in a child class? - greshnik 2:19 pm
      • 2
        And from where the parent class should know about it? These descendants may know about inherited members and methods (not always, however), but not vice versa. - yozh
      • I am confused, sorry in the parent variable is initialized, and in the child I am trying to use it. In general, the question is interesting, I found the answer, it is a pity that they did not immediately understand me. It turns out that variables cannot be initialized; other class variables need to be used, then everything works. It’s too bad that you didn’t understand the question and started minus, believe me, to distinguish undefined variable, and undefined '"', '.' I can. - greshnik
      • You should learn some terminology, then, probably, the wording would be more understandable. The class has fields and methods. And in general it is necessary to immediately proceed to the separation of methods and data, IMHO. The field must be private, but methods for reading / writing data in this field may already be public or protected. Then such confusion does not exactly arise in the child class. - Dex

      In short, ling is right, declare a variable in the current class, or refer to it accordingly:

       \ClassName::getSqlDatabase(); 

      or:

       $ClassLink->sql_database; 

      $ ClassLink - you can drag along with you as a function parameter, or you can, for example, via global:

       global $ClassLink; $ClassLink->... 

      And you will be happy :)

      UPD: I completely forgot about parent :) This is another option, but it's hard to say specifically - you need to see the structure :)

       parent::... 
      • This is a terrible curvature - cy6erGn0m
      • I didn’t design the project :) I’m answering what has already been done and described in the question - I don’t see any other options :) - Alex Silaev