priority
Standard
status
Closed
resolution
Fixed

qcodo
0.4.11 (development)
category
QForm / QControls (PHP)
php
Any

Votes
There are no votes for this issue.

reported: tuesday, january 12, 2010, 8:07 pm pst  |  by: Fernando Lordán  |  messages: 7 messages  |  last: about 3 months ago


#1  |  Fernando Lordán (Barcelona, CAT, Spain) Spain
Tuesday, January 12, 2010, 8:07 PM PST

Around lines 160 and 260 of QFormBase.class.php, in the Run() method, the current working form is “globalized”. I really see no need for this, as there can only be one QForm per page and the $_FORM global is used when needed.

But the first strange thing is that it's innecessarily “globalized” twice. Twice when the form is loaded and twice when it's created. I guess it's a double typo.

QFormBase.class.php

<?php
[...]

if (
$objClass) {
    global $
$strFormId;
    $
$strFormId $objClass;

    
$objClass->strCallType $_POST['Qform__FormCallType'];
    
$objClass->intFormStatus QFormBase::FormStatusUnrendered;

    if (
$objClass->strCallType == QCallType::Ajax)
        
QApplication::$RequestMode QRequestMode::Ajax;

    
// Globalize and Set Variable
    
global $$strFormId;
    $
$strFormId $objClass;

[...]

    global $
$strFormId;
    $
$strFormId $objClass;

    
// By default, this form is being created NOT via a PostBack
    // So there is no CallType
    
$objClass->strCallType QCallType::None;

    
$objClass->strFormId $strFormId;
    
$objClass->intFormStatus QFormBase::FormStatusUnrendered;
    
$objClass->objControlArray = array();
    
$objClass->objGroupingArray = array();

    
// Globalize and Set Variable
    
global $$strFormId;
    $
$strFormId $objClass;

[...]

?>

The second thing is stranger. It seems to me that in the QFormBase::Run() static method all the QForm instance properties are accessed using its “internal” name. In fact it works, but... how are protected instance properties accessed from a static method?

#2  |  ‹‹ Qcodo System Message ››
Tuesday, January 19, 2010, 3:51 PM PST

Fernando Lord made content edits to the issue

#3  |  Mike Ho (Sunnyvale, CA) United States of America Qcodo Administrator
Thursday, April 22, 2010, 10:48 AM PDT

Thanks for the post.  This should now be fixed and has been committed to http://github.com/qcodo/qcodo/commit/45c7715583ff145aaf123b8411c4eb9d55c7361f

This should be in the 0.4.15 release.

#4  |  ‹‹ Qcodo System Message ››
Thursday, April 22, 2010, 10:48 AM PDT

Mike Ho made edits to the issue, including:

  • Status changed from New Issue to Fixed
#5  |  Fernando Lordán (Barcelona, CAT, Spain) Spain
Thursday, May 6, 2010, 1:15 PM PDT

Maybe the last part of the issue report was a little hidden after the code:

As seen in the code snippet, it seems that in the QFormBase::Run() static method all the QForm instance properties are accessed using its “internal” protected name. In fact it works, but... how are protected instance properties accessed from a static method?

Magic? PHP bug? Something escapes to my knowledge here.

#6  |  Mike Ho (Sunnyvale, CA) United States of America Qcodo Administrator
Tuesday, May 18, 2010, 6:45 AM PDT

Not sure if you are referring to variable access level protection or if you are referring to accessing instance variables within a static method context, but I'll address both.

Since the static method is a member of QFormBase, any private or protected variable access for QFormBase variables within that method is allowed.  This is similar to having a object method access protected or private variables within another object of the same class (which is also allowed):

<?php
    
class SomeClass {

        
/**
         * @var string $strPrivate
         */
        
private $strPrivate;

        public function 
Compare(SomeClass $objToCompareAgainst) {
            return (
$this->strPrivate == $objToCompareAgainst->strPrivate);
        }
    }
?>

In terms of accessing instance variables, you are right in that you cannot access instance variables belonging to “$this” within the static method context -- but note that Run() accesses the instance variables of $objClass and NOT of “$this”.  $this is never used.

#7  |  ‹‹ Qcodo System Message ››
Tuesday, May 18, 2010, 2:21 PM PDT

Mike Ho made edits to the issue, including:

  • Status changed from Fixed to Closed
  • Resolution changed from none to Fixed


Copyright © 2005 - 2010, Quasidea Development, LLC
This open-source framework for PHP is released under the terms of The MIT License.