Re: DB_DataObject_FormBuilder: Silent failures OK?
| From: | Justin Patrin | Date: | Thu, 02 Mar 2006 21:59:26 +0000 |
| Subject: | Re: DB_DataObject_FormBuilder: Silent failures OK? | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-23206@lists.php.net to get a copy of this message | ||
On 3/2/06, philip reed <philipreedtech@gmail.com> wrote:
> I'm a bit new to PEAR so forgive me if this question is somehow naive
> or out of tune with the PEAR development culture.
>
> I tried to install DB_DataObject_FormBuilder, but I neglected to
> install all the dependencies. (I knew I needed to install them,
> since I can't get the PEAR autoinstaller to work, but I just forgot to
> install HTML_QuickForm.)
autoinstaller? go-pear.org should be able to install PEAR on your
system. If it doesn't then ask for help or file a bug (if you know
it's a bug). After that the pear installer should be used for
installing PEAR packages. You should never "install" manually as some
things simply won't work.
> I then tried to run the following harness
> code, pretty much taken from the DB_DataObject_FormBuilder doc adapted
> to one of my class names:
>
> error_reporting(E_ALL);
> echo "Hello";
> $teacher =& new DataObjects_Posi_teachers();
Use the factory.
$teacher =& DB_DataObject::factory('posi_teachers');
And make sure you're turning off overloading for DO if you're using PHP4.
> $form =& DB_DataObject_FormBuilder::create($teacher);
>
> The resulting HTML looked like this:
>
> Hello
>
> Or, within the content of the HTML page that was including the above PHP:
>
> <div style='margin:auto;'>Hello
>
> That's it -- no error message of any sort.
>
> Is it standard practice for PEAR packages to fail silently when
> they're misinstalled? Would it be legitimate to submit a patch for
> this, or is a silent failure to be expected in this case?
>
> Incidentally, once I installed HTML_Common and HTML_QuickForm
> everything worked. I just find it surprising that a mature PEAR
> package wouldn't point me to the cause of the failure.
>
In general you should see an error from PHP when a requirement cannot
be found. The PEAR installer is the thing which takes care of
installing dependencies. It generally doesn't make sense to check all
of these things at runtime sine they're supposed to be installed
anyway and it would only waste cycles on every single page load.
However, you did hit something in FormBuilder that should be changed
(well, now it *is* changed, check CVS ;-). The factory (create) was
using @ with include_once to silence include errors to allow a
PEAR_Error to be sent back. But this was silencing the error for the
require_once of HTML/QuickForm.php. I've changed create() to use a
better factory algorithm (the one I just comitted to Text_Wiki,
actually). Now include errors such as this should show up as PHP
errors.
(If you have problems like this in the future you can define a PHP
error handler callback which will catch all PHP notices, warnings, and
errors, regardless of whether the call was silenced with @. See
set_error_handler())
In the future, however, use the PEAR installer.
--
Justin Patrin