Problem accessing Pear methods using Xampp on Windows 7 Home Prem

I want to learn how to utilize classes and functions from Pear and I have been struggling for a few days and need some help.I’m reading PHP Anthology and validating a users FORM input is a great starting point for me. I’m sure my problem is with the configuration because I can run a check_pear.php program to

require_once 'System.php';
var_dump(class_exists('System',false));

and get a bool(true) in the browser.

Also I get the help list when issuing a ‘pear help’ from the command prompt

When I run the pear_validate.php file (these files are from the book) I get:
Fatal error: require_once(): Failed opening required 'Validate.php' (include_path='.;C:\xampp\php\pear') in C:\xampp\htdocs\phpTest\phpant2-master\chapter_03\examples\pear_validate.php on line 10

I’m running PHP Version 7.2.5 which I edited the php.ini files include_path which shows in my browsers phpinfo();
include_path is .;C:\xampp\php\pear

Also I set a Environment Variable User variable PATH C:\xampp\php

What is confusing to me is the two Pear folders I see C:\xampp\php\pear\PEAR that contains the validate.php file. I tried setting the include_path to that directory which is obviously the wrong way to go.

I would appreciate any help.
Bryan

That doesn’t look correct to me. Why the leading .; ?

The default XAMPP include_path on Windows does appear to include both the dot and semicolon. Mine is

include_path=".;C:\xampp\php\PEAR"

-I took the .; out and it still doesn’t work but it looks more correct looking at the phpinfo()

include_path C:\xampp\php\pear

I changed pear to uppercase too…

I went back to include_path=“.;C:\xampp\php\PEAR”

each time I stop and start Apache server and reload the page and I see the changes I make each time come up in the Fatal Error message.

I confess I’ve never used PEAR. Perhaps this article, whilst rather old, might help?

Haven’t used pear my self either but considering their description “PEAR - PHP Extension and Application Repository - PEAR is a framework and distribution system for reusable PHP components.” and the fact that their latest news article is from February 2017 I would go for Composer instead. Composer is a breeze to use.

Oh, maybe that’s “.” for “current directory” and semi-colon separators for a list of other directories.

1 Like

It is, yes

1 Like

I thought the “dot semi-colon” meant more like “the existing PATH” i.e. append this to it.

For example, my PATH has locations for Java, Go, MySQL, etc. bin folders so I can run bat and exe files from the command line.

It’s been a while since I’ve worked it’s PEAR, but I recall having similar “two pear folders” problems before. IIRC, the issue was that many packages expected it to be installed using gopear, and when I installed them not using gopear I needed to figure out how gopear would have installed it and then do the same (all dependencies of the correct versions in the correct locations). Fun, Not.

As for the two pear folders, I think some confusion comes from the package and the class having the same name. One pear folder for the package, and another for the class.

Anyway, unless you’re a human package manager, I strongly recommend you look into using gopear.

PEAR and composer are two completely different things. PEAR manages php extensions and composer manages php libraries ie. things written in php not c.

I’ve never tried to install PEAR packages on XAMP. That sounds like it would be a very painful experience. I have used the below website to build a vm with PEAR dependencies. It was super simple.

https://puphpet.com/

XAMP is good for very simple website builds. However, once you start needing extensions and other tools it kind of falls flat on its face. Using a vm is much better approach to local development than xamp. Especially with tools like puphpet.

1 Like

I guess my immediate goal is to learn to utilize php libraries and scripts. I will check in to Composer. I was reading PHP & MYSQL: Novice To Ninja and he was instructing to install VirtualBox. That didn’t work out to well. What is the advantage of developing on a vm other than testing a site on different operating systems? I think I read where some scripts can only be used in Linux.

That is what had me so confused, pear package folder and PEAR class. To use gopear would I just delete the PEAR class folder and then go with the gopear instructions?

I’m going to check out composer. Thank you

I think what ever path you take there will be some of a learning curve. Although it is a good thing to know how to do more, it might be a good idea to start with the path of least resistance and learn the other ways later. You don’t want to let hurdles stop you from making any progress at all. In other words, learning Virtual Machines is a very valuable asset, but not a necessity.

There is some of PHP that will only work with a certain environment. But the documentation makes it explicit when that’s the case. I wouldn’t worry too much about that now. You’ll find out what those are when you need to use them and can cross that bridge when you get to it. My guess is that unless you ever need to get into the Windows OS it will be a bridge you never get to.

It might install over it, but I think to be safe it would be a good idea to delete or at least rename any PEAR related files that you installed.

You’ll find different ways of running gopear. i.e. bat, phar, php - Probably the easiest would be to download this file to your htdocs folder (assuming you haven’t set up virtual hosts in your apache server) and go to it (eg. http://localhost/go-pear.php) using your browser.

# Webbased installation:
# 1) Download this file and save it as go-pear.php
# 2) Put go-pear.php on your webserver, where you would put your website
# 3) Open http://yourdomain.example.org/go-pear.php in your browser
# 4) Follow the instructions, done!

1 Like

that all sounds like the path I need take. Learning how to access and utilize Pear functions is a step I need to conquer. Thank you very much.

I ended up restoring my Windows 7 back a few days to back out of the VM install.

I actually tried this the other day and tried again now. This is what I did.

  1. First I renamed the PEAR class folder to __PEAR.
  2. Saved the go-pear.php file in my htdocs directory.
  3. opened browser to http://localhost/go-pear.php

Fatal error: Uncaught Error: Call to undefined function ereg() in C:\xampp\htdocs\go-pear.php:1451 Stack trace: #0 C:\xampp\htdocs\go-pear.php(171): detect_install_dirs() #1 {main} thrown in C:\xampp\htdocs\go-pear.php on line 1451

(171) detect_install_dirs();

(1451) if(!ereg(“:”,$php_bin))

I have a configuration problem php.ini ?

No, it’s been a while since I used gopear and I would have thought they kept up-to-date, but obviously not.

ereg has been deprecated for a long time and is not in PHP ver 7+
http://php.net/manual/en/function.ereg.php
http://php.net/manual/en/function.preg-match.php

The good news is you should be able to fix that error with a simple edit.

        } else {
            if(!ereg(":",$php_bin)){
                $php_bin = getcwd().DIRECTORY_SEPARATOR.$php_bin;
            }

to

        } else {
//            if(!ereg(":",$php_bin)){
            if(!preg_match(":",$php_bin)){
                $php_bin = getcwd().DIRECTORY_SEPARATOR.$php_bin;
            } 

The bad news is if this obsolete function is in the script there may be others. Hopefully not, as far as hope can go.

1 Like

Alright it worked sort of. lol you left the first “if” on there.

Now I’m in business after a lot of time fretting over this. Thank you so much.

You didn’t notice the two slashes? They “comment out” that line. You can delete that line entirely, but I comment out instead out of habit. In case my fixing something breaks something else, I like to easily go back before trying something else. But for this relatively minor one line change it doesn’t really matter. Glad you got things working!