Saturday, February 21, 2009

"Class 'XSLTProcessor' not found"

the other day i was trying an example from an xsl tutorial and couldn't get it to work, instead i got the error message "Class 'XSLTProcessor' not found".

here is how i solved it:

first i thought my php versions were not up to date. i'm running php4 and php5 with Apache 1.3 under OS Windows XP. i downloaded the Windows Binaries ZIP folders, unpacked them and placed the contents into my c:\php4 and c:\php5 directories respectively and re-started Apache. trying the example again i still got the same error message.

i thought that maybe something wasn't right in the php.ini files. therefore i made a copy of the php.ini-recommended and renamed it php.ini. i opened the php.ini file with WordPad and searched the document for xsl. the search went to the line that reads ;extension=php_xsl.dll. i uncommented that line by removing the semi-colon. now the line reads: extension=php_xsl.dll. After re-starting the server again i tried the script example once more and still got the same error message: "Class 'XSLTProcessor' not found".

alright ... i was wondering which php.ini file php was looking at and saved the following code snippet in a file named test.php:


<?php
phpinfo();
?>


after i ran this test.php file php displayed the current settings and i found that it was not looking for the php.ini file in the c:\php4 or c:\php5 directories at all, but in the c:\WINDOWS directory.

okay ... i looked for that php.ini file in the c:\WINDOWS directory, opend the file, searched for xsl again and made the change as described above.

after re-starting the server and running the script example again, believe it or not, it still gave me that error message. things like that can become quite frustrating, especially if one tests a script in the localhost environment where it won't and at the webhosting server, where it may work.

i'm not giving up so easily. i knew that the xsl extension under windows is a .dll file that can be found in the ext dirctory. and i also knew that this was a feature only introduced with php5. i checked to see if the php_xsl.dll file existed in the ext folder, which it did; then i went back to the php documentation to see how i would have to set up php under windows and came across this comment: http://de2.php.net/manual/de/book.xsl.php#65277.

alright, so i had to change the path to this ext directory.

i had the php.ini file still open (WordPad) and searched for extension_dir. the line read:

extension_dir = "./"

which i changed to read:

extension_dir = "./ext"

re-starting the Apache Server one more time and running the example script once more at last i saw the expected result on the screen and could go to rest happily after all.

so before someone else has to battle with this issue:
first: check to see if the php_xsl.dll file exists;
second: check to see which php.ini file you gotta change;
third: uncomment ;extension=php_xsl.dll and change the extension directory to extension_dir = "./ext" in the relevant php.ini file.

... and don't forget to re-start the Apache Server!

Good Luck!

tom.paine


No comments: