Reference Methods in another class. how can this problem be solved?

Source: Internet
Author: User
Class reference methods in another class, how can there be no database-class SQL. php has a configuration file config. php, which contains the new data connection class to get the class name $ db in an operation file aa. introduce config in php. php in aa. in php, the primary class name is Aa. I want to use database-class SQL in Aa. a method in php, but the ecli class references the method in another class, how can it not work?
There is a database-type SQL. php
There is a configuration file config. php, which contains the new data connection class to get the class name $ db
Introduce config. php in the aa. php file.

In aa. php, a class name Aa is specified. I want to use a database SQL. php method in Aa, but eclipse does not prompt the method (obviously the reference fails)
However, I reference the method outside the Aa class. eclipse prompts the method.


Why? it is difficult for a method in a class to reference the method of another class?



------ Solution --------------------
Yes!
You can instantiate it externally and pass it as a parameter to the class.
You can declare global variables in external instantiation
You can instantiate it in the class.
You can also pass in through tired static attributes.
You can also use it in Singleton mode.

------ Solution --------------------
Discussion
There is a database-type SQL. php
There is a configuration file config. php, which contains the new data connection class to get the class name $ db
Introduce config. php in the aa. php file.

In aa. in php, the primary class name is Aa. I want to use database-class SQL in Aa. a method in php, but eclipse does not prompt the method (it is obvious that the reference is not successful) <-this is not necessarily because the reference is not successful, and the IDE syntax prompts sometimes not great.
However, I reference the method outside the Aa class. eclipse prompts the method.


Why ......

------ Solution --------------------
Discussion

In config. php, I instantiated $ db.
I referenced config. php in aa. php.
As mentioned above, I directly
$ Db-> method
You can.
However, it is actually not possible.

------ Solution --------------------
It's time to blame eclipse. he cannot identify objects loaded at runtime !?
It's really amazing
------ Solution --------------------
I will introduce the config. php file in a method of the Aa class later.
But it still cannot be used?

This method should be usable, but not other methods.
------ Solution --------------------
Discussion

I will introduce the config. php file in a method of the Aa class later.
But it still cannot be used?

This method should be usable, but not other methods.

------ Solution --------------------
It's amazing.

Discussion

Reference:

I will introduce the config. php file in a method of the Aa class later.
But it still cannot be used?

This method should be usable, but not other methods.


? Are you a xxx vest? Xxx is your vest?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.