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).

Community
  • 1
  • 1
tim
  • 1,999
  • 17
  • 32

2 Answers2

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

maxhb
  • 8,554
  • 9
  • 29
  • 53
  • 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? – tim Dec 18 '15 at 13:59
  • 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. – tim Dec 18 '15 at 14:01
  • 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. – maxhb Dec 18 '15 at 14:01
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.

Dragos
  • 1,824
  • 16
  • 19
  • 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). – tim Dec 18 '15 at 13:54
  • 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 – Dragos Dec 18 '15 at 15:14