When i want to use xml libraries in php i get this error
Fatal error: Call to undefined function domxml_new_doc() in C:\AppServ\www\direction\db2xml.php on line 5
how can i solve it ?
The domxml_new_doc() function is from the PHP4 DOM extension. It has been moved to the PECL repository and is no longer bundled with PHP as of PHP 5.0.0. PHP5 introduced a number of improved extensions to work with XML:
It will, however, never be released with PHP 5, and will only be distributed with PHP 4. If you need DOM XML support with PHP 5 you can use the DOM extension. This domxml extension is not compatible with the DOM extension.
See my answers to
Best XML Parser for PHP
PHP what is the best approach to using XML? Need to create and parse XML responses
If you are working with older code from PHP4 and wish to migrate the code to work on a php5 server with minimal effort, check out the following:
http://www.silicon-vision.com/wp/quickpost-php4-domxml-to-php5/
Simply drop in the include file and reference it at the start of the file that is failing, and it will simply just work like it used to. Not much else to it really. Used it on several older sites after migrating them to a new VPS earlier this year and was quite pleased at solving the issue without having to sit there and rewrite someones spaghetti code :)
Update 2015: I no longer maintain the old blog linked to above, however you can find the domxml tool here: https://alexandre.alapetite.fr/doc-alex/domxml-php4-php5/index.en.html
Check that you have the module enabled and also that you have all required libraries.
May be you have forget to uncomment or add
extension=php_domxml.dll
in your php.ini file?
Related
I wish to be able to do something like:
php --determine-oldest-supported-php-version test.php
And get this output:
7.2
That is, the php binary checks test.php for all function calls or syntax used, and then spits out the oldest version of PHP which would be able to run the script.
The purpose would be for me to create a script which goes through all the .php files in my library/framework and figures out which version of PHP I should consider to be the "oldest supported version".
Currently, I'm doing this manually. Whenever I knowingly use a new feature, function or syntax, I bump up a variable to "7.4" or whatever, and then compare the currently used PHP version against that on runtime. This is not ideal, as you can imagine, and I could very well forget to bump up this value or bump it up too much, or too little, etc.
It would be much nicer to be able to determine this automatically, with such a feature in PHP itself.
I have of course looked through the list of options and PHP has no such feature as far as I can tell. Since I basically answered my own question right away, are there any plans on such a feature in the future?
The only guarantee given is that PHP will remain compatible within the same major version.
You may be interested in looking at the article
Why You Should Be Using Supported PHP Versions.
The tool you are looking for is the GitHub project
PHP_CodeSniffer,
further described in the article
PHPCompatibility update.
You may run it using a command such as:
phpcs --standard=PHPCompatibility --runtime-set testVersion 5.4 <path-of-your-php-files>
I'm using SimplePie with PHP 5.2.17 to parse my RSS feeds through the WordPress plugin feedwordpress. This works well and without problems if I make sure to use this patch to simplepie (in the file IRI.php).
However, if I change my PHP to use version 5.3.28 - the memory leak (or some other memory leak) starts and my site crashes. Any idea what might be causing it / how to solve it?
(or in other words, is there a reason this patch should work in 5.2 and not in PHP 5.3?)
Thanks.
PHP 5.3 isn't fully backward compatible with PHP 5.2,
In your case, the use of the clearstatcache() is probably the cause of the memory leak.
As you can see in the Migrating from PHP 5.2.x to PHP 5.3.x document:
clearstatcache() no longer clears the realpath cache by default.
This issue can be fixed by explicitly setting the $clear_realpath_cache parameter to true
clearstatcache(true)
Im trying to compile phpurple. Im doing everything according to the documentation:
hxxp://phurple.php.belsky.info/ch02.html
but "make" gives me an error:
/myhomedir/phpurple/purple.c: In function ‘call_custom_method’:
/myhomedir/phpurple/purple.c:1370: error: ‘zend_fcall_info’ has no member named ‘object_pp’
/myhomedir/phpurple/purple.c:1408: error: ‘zend_fcall_info_cache’ has no member named ‘object_pp’
I`ve found other people with the same problem:
hxxp://www.mail-archive.com/monetdb-bugs#lists.sourceforge.net/msg05515.html
hxxp://belsky.info/archives/23-Phurple-per-se-PHPurple.html
but nobody gives any information about successful php 5.3 build and the message
PROJECT IS CLOSED if you want
commercial support for php 5.3, let me
know ... )
does not help at all.
does anyone have any idea how to compile it or any clue how to fix the problem ?
P.S. Sorry about the links, some strange StackOverflow limitation
According to phpurple requirements:
Please let me know, if you've successfully compiled on
earlier versions. Actually the extension is being developed
on the php v5.2.6 with the option to be upcomming php v5.3
compatible.
The authors will need to update their source. However, since you have the source you could update it yourself because you noted that the project is CLOSED. You could also fork the code and create your own gitHub project with php 5.3 support.
Good luck.
What you are seeing is PHP's shifty interface (ahem, hold your down votes, I said s h i f t y). By that, I mean function prototypes are subject to change from version to version. Take this meta example:
int foo_call_bar(const char *foobar, size_t len);
And in a later version of something, the function calculates the length dynamically, thus eliminating the second variable in the prototype:
int foo_call_bar(const char *foobar);
Some projects strive to always maintain backwards compatibility to alleviate this headache, which could be accomplished with pre-processor directives that prototype the new implementation with the len variable, but just don't do anything with it. If PHP did that, the code base would succumb to even more madness.
Unfortunately, you'll have to modify phpurple to present the correct arguments to the correct PHP functions, and ensure that they are of the appropriate type. That would be a bit of an undertaking, but probably wouldn't be as difficult as it seems.
The Linux kernel's VFS interface is the same way, and I'm often tasked with porting older experimental file systems to work on modern kernels.
look at that man
http://sourceforge.net/news/?group_id=235197&id=296063
A little late, but here is the latest library that works with PHP 5.3:
The new project page is: http://sourceforge.net/projects/phurple
The blog post: http://belski.net/archives/23-Phurple-per-se-PHPurple.html
I have ran into a problem after I have complied it and added the extension to PHP.ini configuration:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/phurple.so' - /usr/lib/php/modules/phurple.so: undefined symbol: ZVAL_ADDREF in Unknown on line 0
To fix this, change the line containing ZVAL_ADDREF in client.c from
ZVAL_ADDREF(PHURPLE_G(phurple_client_obj));
to
Z_ADDREF_P(PHURPLE_G(phurple_client_obj));
Well, the new URL seems to be a persistent repo with fixes to PHP-5.3 and above. Maybe that should be mentioned, but that won't help with checking it out anyway. For me it worked fine, so I would say it is worth a try.
You can check the new sources shortly posted on https://github.com/weltling/phurple
Is it possible to check syntax of php-code (without running),
similar to the
php-cli -l
when running php the "ordinary" way (as a module)?
There are also some PECL extensions which parse PHP code for various reasons. First there is BCompiler, which can compile a PHP into byte code. Since this step requires parsing the PHP code, I would expect errors if it isn't lint. Parsekit allwos you to compile PHP code to OP codes, which is basically what you desire. However, the extension did not have a release since late 2009, so it might be outdated. Parse_Tree is sadly unmaintained since 2007, but its purpose is to parse a PHP file into an AST. Maybe you can get to something with this one, after some polishing.
PHP_Parser is a PEAR package, which does not rely on special PHP extensions and attempts to parse PHP code from within PHP. Its marked alpha and unmaintained, but it might give you a basis to experiment with.
You can try to run a tool like PHP Depend on the sources, which attempts to parse the given PHP files into an abstract syntax tree. While this might not catch all PHP parser errors, it will already catch quite a lot of them.
You get nice software metrics as an additional goodie, if the code is valid. :)
Is it possible to check syntax of php-code (without running), similar to the php-cli -l
when running php the "ordinary" way (as a module)?
I think the question everyone missed is that there is no difference in PHP syntax whether you run it as a module, or simply execute the binary from a shell: the PHP syntax is the same on both occasions. So, you might as well just use php -l filename.php, as that has the exact same result as using the tools listed above.
For getting the same result as php-cli -l, use the function: php_check_syntax
So I was reading about PHP namespaces, and I realized that in versions earlier than 5.3, if you write
namespace MyNamespace
you get a parse error.
Is there any way to avoid this i.e. make namespaces backwards-compatible, so the code doesn't simply crash?
Short Answer: No.
Longer Answer: (added to capture useful information from other deleted answers). The new Syntax will cause parse errors in PHP, so you can't use a customer error handler to catch errors generated in versions < 5.3. In theory you could write a pre-processor the scans and/or does a lex/parse on the source and then write something back out that would be PHP 5.2 compatible, but that creates more problems than it solves.
Perhaps you could query the version of PHP being used and call eval if it's high enough. I don't know if that will work though.
Actually, I think it's possible, but I don't believe it's worth it. The idea would be to create a custom default stream wrapper, which will parse PHP files according to the new grammar and make the appropriate changes to the syntax so that it will be valid PHP < 5.3.
The wrapper would have to replace class names such as Foo\Bar\Baz with Foo_Bar_Baz. Currently I'm not sure if there's something that would render this impossible.
Anyway, I don't believe it's worth the effort. Upgrade to PHP 5.3.
Oh, that means that the wrapper code should be compatible with PHP < 5.3.
I know this is a very old question, but I needed to make a couple of instructions with namespaces backward compatible with a very old PHP installation (5.2).
What I finally did to avoid parse errors was:
if(version_compare(PHP_VERSION, '5.3.0') >= 0) {
include("file_with_namespaces_code.php");
}
else{
echo("put php 5.2 code here");
}