1#! /usr/local/bin/php -n
2<?php
3
4/*
5   +----------------------------------------------------------------------+
6   | PHP Version 7                                                        |
7   +----------------------------------------------------------------------+
8   | Copyright (c) 1997-2006 The PHP Group                                |
9   +----------------------------------------------------------------------+
10   | This source file is subject to version 3.01 of the PHP license,      |
11   | that is bundled with this package in the file LICENSE, and is        |
12   | available through the world-wide-web at the following url:           |
13   | http://www.php.net/license/3_01.txt                                  |
14   | If you did not receive a copy of the PHP license and are unable to   |
15   | obtain it through the world-wide-web, please send a note to          |
16   | license@php.net so we can mail you a copy immediately.               |
17   +----------------------------------------------------------------------+
18   | Authors: Marcus Boerger <helly@php.net>                              |
19   +----------------------------------------------------------------------+
20 */
21
22/* This script lists extension-, class- and method names that contain any
23   underscores. It omits magic names (e.g. anything that starts with two
24   underscores but no more).
25 */
26
27$cnt_modules = 0;
28$cnt_classes = 0;
29$cnt_methods = 0;
30$err = 0;
31
32$classes = array_merge(get_declared_classes(), get_declared_interfaces());
33
34$extensions = array();
35
36foreach(get_loaded_extensions() as $ext) {
37	$cnt_modules++;
38	if (strpos($ext, "_") !== false) {
39		$err++;
40		$extensions[$ext] = array();
41	}
42}
43
44$cnt_classes = count($classes);
45
46foreach($classes as $c) {
47	if (strpos($c, "_") !== false) {
48		$err++;
49		$ref = new ReflectionClass($c);
50		if (!($ext = $ref->getExtensionName())) {;
51			$ext = $ref->isInternal() ? "<internal>" : "<user>";
52		}
53		if (!array_key_exists($ext, $extensions)) {
54			$extensions[$ext] = array();
55		}
56		$extensions[$ext][$c] = array();
57		foreach(get_class_methods($c) as $method) {
58			$cnt_methods++;
59			if (strpos(substr($method, substr($method, 0, 2) != "__"  ? 0 : 2), "_") !== false) {
60				$err++;
61				$extensions[$ext][$c][] = $method;
62			}
63		}
64	}
65	else
66	{
67		$cnt_methods += count(get_class_methods($c));
68	}
69}
70
71$cnt = $cnt_modules + $cnt_classes + $cnt_methods;
72
73printf("\n");
74printf("Modules: %5d\n", $cnt_modules);
75printf("Classes: %5d\n", $cnt_classes);
76printf("Methods: %5d\n", $cnt_methods);
77printf("\n");
78printf("Names:   %5d\n", $cnt);
79printf("Errors:  %5d (%.1f%%)\n", $err, round($err * 100 / $cnt, 1));
80printf("\n");
81
82ksort($extensions);
83foreach($extensions as $ext => &$classes) {
84	echo "Extension: $ext\n";
85	ksort($classes);
86	foreach($classes as $classname => &$methods) {
87		echo "  Class: $classname\n";
88		ksort($methods);
89		foreach($methods as $method) {
90			echo "    Method: $method\n";
91		}
92	}
93}
94
95printf("\n");
96
97?>