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 » Database » DB_DataObject_FormBuilder » Bug #917

QuickForm Object passed by value to DataObject::postGenerateForm() method

Details

Submitted2004-02-27 12:55 UTC
Frombubik at acvyskov dot cz
Assignedmw21st
StatusClosed
PackageDB_DataObject_FormBuilder
PHP Version4.3.3
OSLinux
Roadmaps(Not assigned)

Comments

[2004-02-27 12:55 UTC] bubik at acvyskov dot cz

Description:
------------
-----Code in my DataObject-derived Class-----
function postGenerateForm(&$form) {
$form->addRule('someelement',"Message!!!",'required');
};
---
With this construction, the Rule is set on a copy of the QuickForm Object. The method postGenerateForm gets this Object prom FormBuilder.php. The original Object is untouched, so I cannot see any Validation Rules in my HTML Form!!!

The Form Object is passed by value instead of by reference.

Here is the patch:
-----Code in your FormBuilder.php-----
if (method_exists($this->_do, 'postgenerateform')) {
- $this->_do->postGenerateForm($obj);
+ $this->_do->postGenerateForm(&$obj);
}
---

[2004-03-14 17:57 UTC] mw21st at php dot net

Passing an object by reference to a method from the "outside" like you propose requires a setting in the php.ini setting to be manipulated ("allow_call_time_pass_reference"). From the php.ini:

; Whether to enable the ability to force arguments to be passed by reference
; at function call time. This method is deprecated and is likely to be
; unsupported in future versions of PHP/Zend. The encouraged method of
; specifying which arguments should be passed by reference is in the function
; declaration. You're encouraged to try and turn this option Off and make
; sure your scripts work properly with it in order to ensure they will work
; with future versions of the language (you will receive a warning each time
; you use this feature, and the argument will be passed by value instead of by
; reference).

Thus, you'd need to do the following in the php.ini:
allow_call_time_pass_reference = On

...otherwise Warnings will be thrown with your solution.

Doing it without the additional "&" works for me. What's your allow_call_time_pass_reference setting?

[2004-03-15 07:54 UTC] bubik at acvyskov dot cz

I restored your version of FormBuilder.php and it works!
I probably added the "&$form" to FormBuilder.php and my class at the same time.
I only need the & operator in my class only.
Thanks for the point.
Close this bug please.

[2004-03-15 12:54 UTC] mw21st at php dot net

Closed :-)