The following code will now throw a PHP notice on the return statement.
<?php function &byReference($value, &$a, &$b) { if ($value$a){ return($a); } ?>
This is because using () around a variable creates a statement out of it. It is only possible to return variables by reference, and not the temporary evaluated value of a statement.
Similarily, the following code will also throw a notice on the return statement:
<?php function &byReference($value, $a, $b) { return$value ? $a : $b; } ?>
Here it seems that you're returning either the variable $a or $b by reference, but that is not the case as you're returning the evaluated value of $value ? $a : $b, which is not a variable but the result of the evaluated statement. Similarily to the first example this will not work
<?php function &byReferenceA(){ return $var } function &byReferenceB(){ return byReferenceA(); } ?>
This is not allowed, as in return byReferenceA();byReferenceA() is a statement (returning a temporary value), not a variable.
This is an exaple that I took from a recent problem that we found in ezmatrixdefinition::xmlString(). See the following excerpt from our code:
<?php foreach ( $this->ColumnNames as $columnName ) { $columnNameNode =& $doc->createElementNode( 'column-name' );/* [1] */ $root->appendChild( $columnNameNode ); /* [2] */ } /* 'createElementNode' has prototype: * function createElementNode( ... ). */ function &appendChild( &$node ) { if ( <a href="http://www.php.net/get_class">get_class</a>( $node ) == "ezdomnode" ) { $this->Children[] =& $node; return $node; } return false; } ?>
As the result xml document contains nodes with the value of last appened child:
<ezmatrix> <column-name id="col_1" idx="1">Col_1 </column-name> <column-name id="col_1" idx="1">Col_1 </column-name> </ezmatrix>
What happens here is:
In [1] $columnNameNode is assigned a new value (and not by reference because createElementNode() returns by value. In two the $columnNameNode is passed as reference to appendChild() where it is assigned by reference to Children[]. In the next iteration this referenced variable is assigned a new value in [1]. Because the Children[] array's first element is still a reference to $columnNameNode, this element is updated too. Then in [2]/[3] it is assigned by reference to Children[] again. Then this cycle starts over again.
Although I'm not exactly sure why this did work with PHP 4.3, the code was previously wrong too. Here is an example of the old code:
<?php function removeForContentObjectAttribute( $contentObjectAttributeID ) { if ( !<a href="http://www.php.net/isset">isset</a>( $this ) or <a href="http://www.php.net/get_class">get_class</a> ( $this ) != 'ezimagefile' ) $this =& eZImageFile::instance(); $this->remove( <a href="http://www.php.net/array"> array</a> ( 'contentobject_attribute_id' => $contentObjectAttributeID ) ); } ?>
In the code above you see that we're reassigning $this to something else, if it did not point to an object of the class ezimagefile. Well, this does not work correctly if this function was called from another object's method as:
<?php eZImageFile::removeForContentObjectAttribute( 42 ); ?>
Because in PHP 4 $this will then point to the previous scope's object, and thus replacing that object instead. For some reasons because of the memory corruptions going on in PHP 4.3 this did not cause any problems. The new correct code looks like:
<?php function removeForContentObjectAttribute( $contentObjectAttributeID ) { if ( <a href="http://www.php.net/isset">isset</a>( $this ) and <a href="http://www.php.net/get_class">get_class</a>( $this ) == 'ezimagefile' ) $instance =& $this; else $instance =& eZImageFile::instance(); $instance->remove( <a href="http://www.php.net/array">array</a>( 'contentobject_attribute_id' => $contentObjectAttributeID ) ); } ?>
Timing: | Jan 18 2025 03:11:55 |
Script start | |
Timing: | Jan 18 2025 03:11:55 |
Module start 'layout' | |
Timing: | Jan 18 2025 03:11:55 |
Module start 'content' | |
Timing: | Jan 18 2025 03:11:55 |
Module end 'content' | |
Timing: | Jan 18 2025 03:11:55 |
Script end |
Total runtime | 0.0683 sec |
Peak memory usage | 4,096.0000 KB |
Database Queries | 23 |
Checkpoint | Start (sec) | Duration (sec) | Memory at start (KB) | Memory used (KB) |
---|---|---|---|---|
Script start | 0.0000 | 0.0057 | 587.7969 | 152.6094 |
Module start 'layout' | 0.0057 | 0.0031 | 740.4063 | 39.4141 |
Module start 'content' | 0.0089 | 0.0580 | 779.8203 | 451.6250 |
Module end 'content' | 0.0669 | 0.0014 | 1,231.4453 | 8.3438 |
Script end | 0.0682 | 1,239.7891 |
Accumulator | Duration (sec) | Duration (%) | Count | Average (sec) |
---|---|---|---|---|
Ini load | ||||
Load cache | 0.0033 | 4.8090 | 15 | 0.0002 |
Check MTime | 0.0012 | 1.7982 | 15 | 0.0001 |
Mysql Total | ||||
Database connection | 0.0011 | 1.5834 | 1 | 0.0011 |
Mysqli_queries | 0.0233 | 34.0836 | 23 | 0.0010 |
Looping result | 0.0002 | 0.3150 | 21 | 0.0000 |
Template Total | 0.0375 | 54.9 | 2 | 0.0187 |
Template load | 0.0021 | 3.0496 | 2 | 0.0010 |
Template processing | 0.0354 | 51.8075 | 2 | 0.0177 |
Template load and register function | 0.0001 | 0.1467 | 1 | 0.0001 |
states | ||||
state_id_array | 0.0008 | 1.2258 | 1 | 0.0008 |
state_identifier_array | 0.0013 | 1.9673 | 2 | 0.0007 |
Override | ||||
Cache load | 0.0018 | 2.6004 | 47 | 0.0000 |
Sytem overhead | ||||
Fetch class attribute name | 0.0015 | 2.2617 | 1 | 0.0015 |
class_abstraction | ||||
Instantiating content class attribute | 0.0000 | 0.0175 | 1 | 0.0000 |
General | ||||
dbfile | 0.0006 | 0.8190 | 10 | 0.0001 |
String conversion | 0.0000 | 0.0105 | 4 | 0.0000 |
Note: percentages do not add up to 100% because some accumulators overlap |
Usage | Requested template | Template | Template loaded | Edit | Override |
---|---|---|---|---|---|
1 | node/view/full.tpl | full/article.tpl | extension/sevenx/design/simple/override/templates/full/article.tpl | ||
1 | content/datatype/view/ezxmltext.tpl | <No override> | extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tpl | ||
5 | content/datatype/view/ezxmltags/header.tpl | <No override> | design/standard/templates/content/datatype/view/ezxmltags/header.tpl | ||
9 | content/datatype/view/ezxmltags/emphasize.tpl | <No override> | design/standard/templates/content/datatype/view/ezxmltags/emphasize.tpl | ||
11 | content/datatype/view/ezxmltags/paragraph.tpl | <No override> | extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tpl | ||
8 | content/datatype/view/ezxmltags/literal.tpl | <No override> | extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tpl | ||
1 | content/datatype/view/ezxmltags/line.tpl | <No override> | design/standard/templates/content/datatype/view/ezxmltags/line.tpl | ||
1 | print_pagelayout.tpl | <No override> | extension/community/design/community/templates/print_pagelayout.tpl | ||
Number of times templates used: 37 Number of unique templates used: 8 |
Time used to render debug report: 0.0001 secs