PHP 5 and unset

ramsalt - March 19, 2007 - 09:57
Project:Link
Version:5.x-1.5
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

There is a problem with the Link module if you use PHP 5. The unset function is not supported for referenced arrays anymore, and this trigger an error on my site. On line 272 I have to uncomment the following line to make it work:

    unset($node_field['attributes']['target']);

This should be fixed, but I can't see how without changing more functions.

#1

gracearoha - March 22, 2007 - 10:36

just tracking

#2

quicksketch - April 14, 2007 - 04:57

I don't believe this is the case. I've used unset all over the place where object and array values are passes by reference. The arrays and objects themselves passed by reference cannot be unset, but their individual keys may be unset just fine. For example:

function myfunction(&$my_array) {
unset($my_array); // Does not affect original referenced variable
unset($my_array['my_key']); // Removes 'my_key' from the original variable
}

This comment on the PHP site gives the same explanation: http://us2.php.net/manual/en/function.unset.php#56661

Drupal core uses this in several places also. Most notably I found it in common.inc as part of drupal_render (look for unset($elements['#prefix'], $elements['#suffix']); after $elements is passed in by reference).

#3

quicksketch - October 21, 2007 - 06:17
Status:active» closed
 
 

Drupal is a registered trademark of Dries Buytaert.