0

Is the source code of the predefined PHP classes (eg Execption, PDO, etc) available somewhere?

I tried printing the source code of the classes via PHP, but it did not work for predefined classes (probably because the source files don't actually exist on my system?).

The reason why I want the source is that I want to know what and how exactly some methods do what they do (for example, what __wakeup does for PDO).

1
  • You can download the php source files from the php.net site Commented Dec 18, 2015 at 13:28

2 Answers 2

2

It's not possible to print out the php source code of those classes as they habe never been written in php. Instead you could have a look at the c sources: https://github.com/php/php-src

Sign up to request clarification or add additional context in comments.

3 Comments

do you know where exactly the predefined classes are in the c source? I found PDO in /ext/pdo, but was not able to find eg Exeption, Datetime, or CURLFile. Is there some structure as to where the classes are?
ok, they all seem to be inside ext, it's just that neither the directory name nor the file name are necessarily the same as the PHP class name. But they can be found by searching for the method name.
Sorry, I really dont know. I would simply clone the git repository and use my IDE to search for those keywords. Feel free to ask another question (#c) on Stackoverflow for help in finding those Classes/Methods.
1

If you really want to see the source of the respective classes, I would just go to the php.net website and download the source code of PHP.

There might just as well be that those classes were not even wrote in PHP.

But do you really need to see the source code of those classes?

In case you want to know what __wakeup() does for PDO, shouldn't you rather read the PHP documentation for magic methods ?

It says there

The intended use of __wakeup() is to reestablish any database connections that may have been lost during serialization and perform other reinitialization tasks.

2 Comments

because the documentation is rather generic. In this case, it's also not about PDO, but about __wakeup in general. I looked it up in the source, and eg for PDO, wakeup just throws an exception (it doesn't reestablish the connection).
As I was saying. The answer is STILL on php.net It's either the documentation, either looking directly in the source code of PHP

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.