PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » HTML » HTML_QuickForm » Bug #3197

Incorrect case in a is_a

Details

Submitted2005-01-14 02:47 UTC
Fromphp at mithis dot com
StatusBogus
PackageHTML_QuickForm
PHP VersionIrrelevant
OSLinux
Roadmaps(Not assigned)

Comments

[2005-01-14 02:47 UTC] php at mithis dot com

Description:
------------
The code in RuleRegistry.php at line 217 reads

if (is_a($element, 'html_quickform_group')) {

it should read

if (is_a($element, 'HTML_QuickForm_group')) {

otherwise it will always evaulate to false.

Reproduce code:
---------------
Patch:

--- RuleRegistry.php.orig 2005-01-14 12:53:53.000000000 +1030
+++ RuleRegistry.php 2005-01-14 12:54:00.000000000 +1030
@@ -214,7 +214,7 @@
{
$jsIndex = isset($index)? '[' . $index . ']': '';
$tmp_reset = $reset? " var field = frm.elements['$elementName'];\n": '';
- if (is_a($element, 'html_quickform_group')) {
+ if (is_a($element, 'HTML_QuickForm_group')) {
$value = " var {$elementName}Elements = '::";
for ($i = 0, $count = count($element->_elements); $i < $count; $i++) {
$value .= $element->getElementName($i) . '::';

[2005-01-15 02:20 UTC] php at mithis dot com

This occurs in php5, specially when using the __autoload option.

PHP5 doesn't find a class called 'html_quickform_group' hence tries to use __autoload to find it.

Use the following code to produce it.

<?php

function __autoload($classname) {
print "Trying to find $classname";
}

$form = new HTML_QuickForm('context', 'get');
$form->addElement('text', 'textfield', 'Some text');
$form->addRule('text', 'Some text is required.', 'required', '', 'client');
$fomr->display();

It will print out "Trying to find html_quickform_group" then the form. If you fix the case in RuleRegistry.php it will only output the form.

[2005-01-15 09:28 UTC] php at mithis dot com

You may define an __autoload function which is automatically called in case you are trying to USE a class which hasn't been defined yet. By calling this function the scripting engine is given a last chance to load the class before PHP fails with an error.

You are using a class when doing a is_a (to check that the current object is an instance of the class), hence __autoload is called.

From the above it is clear that if __autoload is being called a class CAN NOT be found.

What is the point of not fixing this, it's a simple one line change and doesn't not change the behaviour in any other instance?

[2005-07-26 16:27 UTC] scott at crisscott dot com

Please reconsider fixing this bug. It is a bug within HTML_QuickForm and not with PHP itself or the implementation of __autoload.

This implementation of __autoload:

function __autoload($class)
{
include_once str_replace('_', '/', $class) . '.php';
}

Should work for any PEAR class that follows the PEAR naming conventions. Even though HTML_QuickForm_group doesn't follow the PEAR naming conventions, proper capitalization would allow the __autoload implementation to work properly.

It is unreasonable to expect every developer that uses HTML_QuickForm and PHP5 to add a special HTML_QuickForm clause to their __autoload function. A quick grep for is_a in my PEAR directory shows that Mail, Log, Net_SMTO, Console_Getargs, Console_Getopt, PHP_Beautifier, and PEAR all use is_a. Should I put in special statements to ignore all of their autoloads as well?