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 $ 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;   

Thanks!

You have to write $ this !

Try 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

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -