After PHP is upgraded to 5.4, the private calling class library cannot be executed.

Source: Internet
Author: User
After PHP is upgraded to 5.4, the private class library cannot be called !!!
After php is upgraded to 5.4
Previously executed functions cannot be executed now.
The entire file structure is as follows:

Class wechatCallbackapiTest
{
Public function valid ()
{
......
Include ('Db. php ');
......
$ ContentStr = $ this-> zhiwen ($ name, $ xuehao );
......
}

Private function zhiwen ($ uid, $ xuehao ){
Include ('Db. php ');
......
}
}

Now, the zhiwen function only needs to include ('Db. php'); the following cannot be executed normally.
The valid call of db. php is normal.

The db. php file is used to call a database class library. the file is as follows:
$ Db_config ["hostname"] = "localhost"; // server address
......
Include ('Db. class. php ');
$ Db = new db ();
$ Db-> connect ($ db_config );
?>

I don't understand the inheritance of functions and class libraries. thank you for your help.


Reply to discussion (solution)

This has nothing to do with PHP upgrade to 5.4!

You are in public function valid ()
Include ('Db. php ');
In private function zhiwen ($ uid, $ xuehao)
Include ('Db. php ');
Db. class. php has a db class definition, which leads to duplicate db class definition errors.
This is not allowed even for php4!

This has nothing to do with PHP upgrade to 5.4!

You are in public function valid ()
Include ('Db. php ');
In private function zhiwen ($ uid, $ xuehao)
Include ('Db. php ');
Db. class. php has a db class definition, which leads to duplicate db class definition errors.
This is not allowed even for php4!



Thank you for your answers!
However, I can write this statement normally before the upgrade.
I tried to delete
Include ('Db. php ');
It is found that operations on the database in the zhiwen function are no longer executable.

As long as your db. class. php has class db {....}
Then, your program cannot run correctly in any version of php.

Yes
Public function valid ()
{
......
Include ('Db. php'); // This may be added later
......
$ ContentStr = $ this-> zhiwen ($ name, $ xuehao );
......
}

Yes
Public function valid ()
{
......
Include ('Db. php'); // This may be added later
......
$ ContentStr = $ this-> zhiwen ($ name, $ xuehao );
......
}



Include ('Db. php') in public function valid ();
I cannot use it after I upgrade lnmp.
Now public function valid ()
And private function zhiwen ($ uid, $ xuehao)
You need to call the database class
Then how can we call include ('Db. php') normally ');
And use the class library?

// The result of multiple references is changed to include_once ('Db. php ');

// The result of multiple references is changed to include_once ('Db. php ');


Thank you for choosing which one to change to include_once ('Db. php ');


// The result of multiple references is changed to include_once ('Db. php ');


Thank you for choosing which one to change to include_once ('Db. php ');



Change both



// The result of multiple references is changed to include_once ('Db. php ');


Thank you for choosing which one to change to include_once ('Db. php ');



Change both


I checked that include_once is used to avoid repeated calls. The second call will automatically filter the same file.
But the second time I got the private function zhiwen ($ uid, $ xuehao ),
You also need to call that class library.
It is useless without calling or inheriting the following database operations.
Is there a way to inherit?

Can someone help solve this problem?

Yes
Public function valid ()
{
......
Include ('Db. php'); // This may be added later
......
$ ContentStr = $ this-> zhiwen ($ name, $ xuehao );
......
}



Hello, if you cannot call the private function zhiwen ($ uid, $ xuehao) repeatedly, how should I use the db Class Library? thank you.

Include ('Db. class. php') in B. php ');
Change to include_once ('Db. class. php ');
Include ('Db. php'); no need to change



// The result of multiple references is changed to include_once ('Db. php ');


Thank you for choosing which one to change to include_once ('Db. php ');



Change both



If you cannot call the private function zhiwen ($ uid, $ xuehao) repeatedly, how should I use the db Class Library? thank you.

Include ('Db. class. php') in B. php ');
Change to include_once ('Db. class. php ');
Include ('Db. php'); no need to change



Thanks.
What is the principle?
Why does it not need to be changed to include_once as long as the database. php file is modified?

When include_once is loaded, it will not be loaded.
Include is always loaded, no matter whether or not it has been loaded
Therefore, classes, functions, and constants cannot be defined in the file that has been included for multiple times. Otherwise, the definition is repeated.

Your db. php has
Include ('Db. class. php'); // contains the definition of the db class.
So when you include ('Db. php'); again, the db class has been defined and an error occurs.

Change to include_once ('Db. class. php'); then, this problem will not occur, because the definition of db will only be loaded once.

When include_once is loaded, it will not be loaded.
Include is always loaded, no matter whether or not it has been loaded
Therefore, classes, functions, and constants cannot be defined in the file that has been included for multiple times. Otherwise, the definition is repeated.

Your db. php has
Include ('Db. class. php'); // contains the definition of the db class.
So when you include ('Db. php'); again, the db class has been defined and an error occurs.

Change to include_once ('Db. class. php'); then, this problem will not occur, because the definition of db will only be loaded once.



Thank you for your explanation.

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.