Page 1 of 1
Compiling a list of php functions
Posted: Mon May 03, 2010 9:28 pm
by PHPHorizons
Hello, I'm wondering if anyone here has thought about compiling a list of php functions, like the what is used for IDE auto complete.
I've thought about using get_defined_functions() and then using reflection, but it turns out that not all php functions have data filled in for use in reflection. For instance, some of the mysql_xxxx functions are listed as having 0 parameters, like mysql_query and mysql_fetch_array. Clearly, those functions are missing something needed to enable reflection to detect their parameters.
A second downside to reflection is that I could not find any doc comments on the internal php functions that I checked. Therefore, those functions would be listed, but have no description.
So, I considered delving into the php manual's source code and I found out that it's using something called docbook and it looks very complicated. I haven't attempted to load any of the php manual xml files into a php script, but I tried it in C# and failed miserably.
Question: Has anyone tried to do this before? If so, how did you do it? How would you recommend to do it?
Cheers
PS The purpose behind this is to build and auto complete. It would work exactly the way an auto complete works in any IDE. I'm exploring what it would take to make an IDE since no IDE on the market fulfills all of my needs. And the goal is to avoid having to hand write all of the auto complete, and even to allow an automated update procedure so that the auto complete can always keep up with improvements in the language.
Re: Compiling a list of php functions
Posted: Fri May 07, 2010 12:22 pm
by PHPHorizons
I've made an attempt at loading the xml files using a php script, but I've failed there as well.
Perhaps if I post the code, someone will be able to help me refine the code. I know this is getting away from general discussion. Since the general topic of compiling a list of functions seems to not be generating any response, maybe I posting some code will generate some responses. If this should be moved to php code, which is where I would have put it if I had originally planned to post code, then by all means, please do.
Code: Select all
<?php
class php_functions {
const dir = 'C:\Users\foo\Work\New IDE\php-phpdoc-en-a3f27b9\reference';
private $function_files = array();
public function getFunctionFiles() {
$this->scanFunctionFiles(php_functions::dir);
return $this->function_files;
}
private function scanFunctionFiles($path) {
// printf('Path: %s, Dirname: %s, Basename: %s', $path, dirname($path), basename($path));
// return;
if (is_dir($path)) {
$files = scandir($path);
foreach ($files as $file_name) {
if (in_array($file_name, array('.', '..'), true)) {
continue;
}
$file_path = $path . DIRECTORY_SEPARATOR . $file_name;
if (basename($path) === 'functions') {
$xml = new SimpleXMLElement(file_get_contents($file_path), null, false, 'http://docbook.org/ns/docbook');
$this->function_files[] = $xml;
} else {
//printf("File: %s, Is Dir: %s\n", $file_name, is_dir($path) ? 'yes' : 'no');
$this->scanFunctionFiles($file_path);
}
}
}
}
}
$php_functions = new php_functions();
var_dump($php_functions->getFunctionFiles());
I've tried creating the xml object like this as well:
Code: Select all
$xml = new SimpleXMLElement(file_get_contents($file_path));
Both methods produce the same errors. Here are some of them in their entirety:
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 11: parser error : Entity 'reftitle.description' not defined in C:\Users\foo\web\Apache2.2\htdocs\function_compiler.php on line 37
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: &reftitle.description; in C:\Users\foo\web\Apache2.2\htdocs\function_compiler.php on line 37
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in C:\Users\foo\web\Apache2.2\htdocs\function_compiler.php on line 37
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 27: parser error : Entity 'reftitle.returnvalues' not defined in C:\Users\foo\web\Apache2.2\htdocs\function_compiler.php on line 37
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: &reftitle.returnvalues; in C:\Users\foo\web\Apache2.2\htdocs\function_compiler.php on line 37
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in C:\Users\foo\web\Apache2.2\htdocs\function_compiler.php on line 37
Here are the contents of the first xml file this script encounters:
Code: Select all
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ -->
<!-- splitted from ./en/functions/apache.xml, last change in rev 1.20 -->
<refentry xml:id="function.apache-child-terminate" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>apache_child_terminate</refname>
<refpurpose>Terminate apache process after this request</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>bool</type><methodname>apache_child_terminate</methodname>
<void/>
</methodsynopsis>
<para>
<function>apache_child_terminate</function> will register the
Apache process executing the current PHP request for termination
once execution of PHP code is completed. It may be used to
terminate a process after a script with high memory consumption has
been run as memory will usually only be freed internally but not
given back to the operating system.
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns &true; if PHP is running as an Apache 1 module, the Apache version
is non-multithreaded, and the
<link linkend="ini.child-terminate">child_terminate</link> PHP directive is
enabled (disabled by default). If these conditions are not met, &false; is
returned and an error of level <constant>E_WARNING</constant> is generated.
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
¬e.no-windows;
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>exit</function></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
Cheers
Re: Compiling a list of php functions
Posted: Sat May 08, 2010 5:24 pm
by Doug G
Or just use PDT Eclipse which already has built-in hooks in the editor to display the function syntax from the php docs.
Re: Compiling a list of php functions
Posted: Sat May 08, 2010 5:43 pm
by Eran
If you're not comfortable using the docbook format, the manual is available for download in HTML and CHM formats as well -
http://www.php.net/download-docs.php
Re: Compiling a list of php functions
Posted: Sat May 08, 2010 6:22 pm
by PHPHorizons
@Doug G: Thanks for the suggestion. I have a long list of reasons why I don't like using Eclipse, not the least of which is the Java layer that substantially reduces the overall responsiveness of any application that uses it (IMHO). It should suffice to say that I'm far more interested in discussing the possibilities of making my own IDE.
@pytrin: I actually have downloaded the tar.gz package and have made a script that uses the PHP Dom extension and the script is capable of pulling all the data I would need for this. As far as docbook, I wouldn't say that I'm uncomfortable with it, I just don't know which direction to go in to parse it with php. The Simple XML class didn't work for me (naturally, someone more talented than I may be able to get it to work with Simple XML, so I can't say that's not the way to go, it just didn't work for me).
I have considered looking into PhD, but haven't gotten around to it yet. I did get Ubuntu installed on my laptop so that I could install PhD, so at some point I'm sure I'll give that a spin. I have doubts about PhD though, it seems that it's geared towards outputting HTML or PDF's or CHM's. I'm did not see anything about PhD outputting the PHP Manual as say an exported php array, or some other serialized format.
Whilst I was able to parse the HTML files with the PHP Dom extension, I'd still be interested in what the best way to do this is.
Cheers
Re: Compiling a list of php functions
Posted: Sat May 08, 2010 6:38 pm
by Eran
You can use PhD on windows, if that's what's stopping you -
http://elizabethmariesmith.com/2009/02/ ... n-windows/
Other than that, it's quite possible SimpleXML is not up to the task of parsing those XMLs. You might want to get familiar with DOMDocument instead -
http://www.php.net/manual/en/domdocument.loadxml.php