[PHP] PHP4 to PHP5 migration with E_STRICT

2010-12-07 Thread Tom Robinson
Hi,

I'm migrating a web application written for PHP4 to PHP5. I've turned on
E_STRICT to have a detailed look at all the code thoroughly. I have a
number of 'Notices' and 'Strict Standards' messages appearing now.

I don't consider myself a PHP guru by any means so I'm seeking help with
understanding these messages and how to fix the code.

One of the messages is:

"PHP Strict Standards:  Only variables should be assigned by reference in"

This is for a class SPControlPanel with a method

function getContentTypes(&$db)
{
$tabledata = array();

$sql = "select
contenttype.*
from
contenttype";

return $db->queryAll($sql, true);
}

The warning is for this segment of code below which is another method in
the same class (marked with comment // this line):

function getCategoryTypes(&$db) {
$tabledata = array();

$myContentTypes = &SPControlPanel::getContentTypes($db); // this
line
foreach ($myContentTypes as $key => $data) {
if ($data['iscategory']) $tabledata[] = $data['contenttype'];
}

return $tabledata;
}

There are many more methods making assignments in a similar way in this
class and in other classes throughout the code.

I'm not sure of the best way to re-code this to resolve the E_STRICT
warning.

Any help is much appreciated.

Regards,

Tom


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP4 to PHP5 migration with E_STRICT

2010-12-07 Thread Tom Robinson
Thanks David.

If my understanding is correct, then:

SPControlPanel::getContentTypes($db);

is a reference to a static instantiation of the class. If so, then it
must be syntactically something like when using 'new' (which returns a
reference) so there's no need to apply the & operator. Am I on the right
track?

I have some more PHP4 code in the application which caused: "PHP
Notice:  Only variable references should be returned by reference". I
have fixed it like this:

<   function & _getTable($cached=true)
<   {
<   return new TableClass($this->_getTableName());
---
>   function & _getTable($cached=true) {
>   $temp = new TableClass($this->_getTableName());
>   return $temp;

Is this acceptable?

I'll have to come back to the $db issue - it's not issuing a warning so
I'll leave it alone until I've tidied up all the other issues.

Regards,

Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] PHP4 vs PHP5 overrides

2011-03-16 Thread Tom Robinson
Hi,

I'm trying to decipher inherited code (I did not write this) and I'm
having great difficulty understanding the override of a method in PHP4
vs PHP5

Here's the code:

form.php
22 class FormClass
23 {
...
/* some method calls to _dispatchSave() */
572 if($this->_dispatchSave($key) === FALSE)
573 {
574 return FALSE;
575 }
...
/* _dispatchSave is defined */
692 function _dispatchSave($key)
693 {

arform.php
17 class ActiveRecordFormClass extends FormClass
18 {
...
/* _dispatchSave is defined */
84 function _dispatchSave(&$key)
85 {

In PHP 4.3.9:

The arform.php implementation of _dispatchSave is called
(i.e.ActiveRecordFormClass::_dispatchSave())in preference to the one
defined in it's own class. This is the desired call BTW but why does
this happening? I would expect the parent implementation to be called,
not a child implementation???

In PHP 5.1.6:

I get the warning:

"PHP Strict Standards:  Declaration of
ActiveRecordFormClass::_dispatchSave() should be compatible with that of
FormClass::_dispatchSave() in ..."

which is expected since the parameters are defined differently. As I
expected, the FormClass::_dispatchSave() implementation is called in
PHP5. This implementation does not have the desired effect (the
application crashes).

What is happening? Maybe I'm not seeing something simple. I look forward
to any responses.

Regards,

Tom






signature.asc
Description: OpenPGP digital signature


Re: [PHP] PHP4 vs PHP5 overrides

2011-03-16 Thread Tom Robinson
My apologies. I've not seen something I should have earlier. Also the
instance that is behind all of this is and instance of
ActiveRecordFormClass.

So, in PHP4, the correct overridden method is called:
ActiveRecordFormClass::_dispatchSave().
In PHP5, the FormClass::_dispatchSave() is called...???

BTW I'm tracing this though with xdebug.

Regards,

Tom

Tom Robinson
System Administrator

On 17/03/11 13:06, Tom Robinson wrote:
> Hi,
>
> I'm trying to decipher inherited code (I did not write this) and I'm
> having great difficulty understanding the override of a method in PHP4
> vs PHP5
>
> Here's the code:
>
> form.php
> 22 class FormClass
> 23 {
> ...
> /* some method calls to _dispatchSave() */
> 572 if($this->_dispatchSave($key) === FALSE)
> 573 {
> 574 return FALSE;
> 575 }
> ...
> /* _dispatchSave is defined */
> 692 function _dispatchSave($key)
> 693 {
>
> arform.php
> 17 class ActiveRecordFormClass extends FormClass
> 18 {
> ...
> /* _dispatchSave is defined */
> 84 function _dispatchSave(&$key)
> 85 {
>
> In PHP 4.3.9:
>
> The arform.php implementation of _dispatchSave is called
> (i.e.ActiveRecordFormClass::_dispatchSave())in preference to the one
> defined in it's own class. This is the desired call BTW but why does
> this happening? I would expect the parent implementation to be called,
> not a child implementation???
>
> In PHP 5.1.6:
>
> I get the warning:
>
> "PHP Strict Standards:  Declaration of
> ActiveRecordFormClass::_dispatchSave() should be compatible with that of
> FormClass::_dispatchSave() in ..."
>
> which is expected since the parameters are defined differently. As I
> expected, the FormClass::_dispatchSave() implementation is called in
> PHP5. This implementation does not have the desired effect (the
> application crashes).
>
> What is happening? Maybe I'm not seeing something simple. I look forward
> to any responses.
>
> Regards,
>
> Tom
>
>
>
>


signature.asc
Description: OpenPGP digital signature


Re: [PHP] PHP4 vs PHP5 overrides

2011-03-16 Thread Tom Robinson
It's funny how talking or writing about something uncovers things you
didn't see before.

In an effort to tidy up the code I heeded the original implementors
comments and made the methods private (they were previously undeclared).
Making them public seems to have fixed the problem.

On 17/03/11 13:20, Tom Robinson wrote:
> My apologies. I've not seen something I should have earlier. Also the
> instance that is behind all of this is and instance of
> ActiveRecordFormClass.
>
> So, in PHP4, the correct overridden method is called:
> ActiveRecordFormClass::_dispatchSave().
> In PHP5, the FormClass::_dispatchSave() is called...???
>
> BTW I'm tracing this though with xdebug.
>
> Regards,
>
> Tom
>
> Tom Robinson
> System Administrator
> On 17/03/11 13:06, Tom Robinson wrote:
>> Hi,
>>
>> I'm trying to decipher inherited code (I did not write this) and I'm
>> having great difficulty understanding the override of a method in PHP4
>> vs PHP5
>>
>> Here's the code:
>>
>> form.php
>> 22 class FormClass
>> 23 {
>> ...
>> /* some method calls to _dispatchSave() */
>> 572 if($this->_dispatchSave($key) === FALSE)
>> 573 {
>> 574 return FALSE;
>> 575 }
>> ...
>> /* _dispatchSave is defined */
>> 692 function _dispatchSave($key)
>> 693 {
>>
>> arform.php
>> 17 class ActiveRecordFormClass extends FormClass
>> 18 {
>> ...
>> /* _dispatchSave is defined */
>> 84 function _dispatchSave(&$key)
>> 85 {
>>
>> In PHP 4.3.9:
>>
>> The arform.php implementation of _dispatchSave is called
>> (i.e.ActiveRecordFormClass::_dispatchSave())in preference to the one
>> defined in it's own class. This is the desired call BTW but why does
>> this happening? I would expect the parent implementation to be called,
>> not a child implementation???
>>
>> In PHP 5.1.6:
>>
>> I get the warning:
>>
>> "PHP Strict Standards:  Declaration of
>> ActiveRecordFormClass::_dispatchSave() should be compatible with that of
>> FormClass::_dispatchSave() in ..."
>>
>> which is expected since the parameters are defined differently. As I
>> expected, the FormClass::_dispatchSave() implementation is called in
>> PHP5. This implementation does not have the desired effect (the
>> application crashes).
>>
>> What is happening? Maybe I'm not seeing something simple. I look forward
>> to any responses.
>>
>> Regards,
>>
>> Tom
>>
>>
>>
>>


signature.asc
Description: OpenPGP digital signature