Can the custom method name be the same as the PDO built-in method name?
谭勇2017-10-12 19:26:04
0
1
1181
Can the custom method name be the same as the existing method name in PDO? For example, isn’t the feach() method customized in the video? However, feach is the default method in PDO
I don’t know what that video is about, I’ll just tell you what I understand
The custom method name can be the same as the method name that comes with PDO. First, you need to figure out the scope. If you If the database class you write yourself does not inherit the PDO class, even if the member attributes and member functions in the two classes are exactly the same, there is no relationship at all. When called, the object instances of the two classes will call the functions in their own classes respectively.
If a custom class inherits the PDO class and then declares a method with the same name as the PDO class, it is overridden. Note thatfetch is a method of the PDOStatement object, so even if the PDO class is inherited, If fetch is customized, then the fetch method defined by yourself is used instead of the fetch of the PDOStatement object;
There is also a situation where a new PDO object is created in the customized class, including the above situation. , there is a problem. After PDO executes query or execute(), it returns the object instance of PDOStatement. If you use this returned instance to execute the fetch method, it is the fetch of the executed PDOStatement.
So, I don’t know how to say it in words, you will know after you practice it
I don’t know what that video is about, I’ll just tell you what I understand
The custom method name can be the same as the method name that comes with PDO. First, you need to figure out the scope. If you If the database class you write yourself does not inherit the PDO class, even if the member attributes and member functions in the two classes are exactly the same, there is no relationship at all. When called, the object instances of the two classes will call the functions in their own classes respectively.
If a custom class inherits the PDO class and then declares a method with the same name as the PDO class, it is overridden. Note thatfetch is a method of the PDOStatement object, so even if the PDO class is inherited, If fetch is customized, then the fetch method defined by yourself is used instead of the fetch of the PDOStatement object;
There is also a situation where a new PDO object is created in the customized class, including the above situation. , there is a problem. After PDO executes query or execute(), it returns the object instance of PDOStatement. If you use this returned instance to execute the fetch method, it is the fetch of the executed PDOStatement.
So, I don’t know how to say it in words, you will know after you practice it