php - Variables set in the constructor are forgotten? -
What I'm trying to do here is to create the variable $ sql_info and set it First is for a default value, then the constructor takes a logic, which will then be set to the $ sql_info variable if I type Thanks! You have to write Try this: $ sql_info; I do it within the Constructor, then it all works fine, but if I try to do it in a different function, then nothing on the screen resonates, even the default value is not . Why is it like this?
& lt ;? Php class connection {Private $ sql_info = "default"; Function __ conversion ($ info) {// $ sql_info $ sql_info = $ Set new value of information; } Function connect () {global $ sql_info; // echoing new set string echo $ sql_info; }}? & Gt;
$ this !
& lt ;? Php class connection {Private $ sql_info = "default"; Set the new value of the function __construct ($ info) {// $ sql_info $$-gt; Sql_info = $ info; } Function connect () {global $ sql_info; // resonate the new set string echo $ this- & gt; Sql_info; }}? & Gt;
Comments
Post a Comment