473,371 Members | 1,455 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,371 software developers and data experts.

Call-time pass-by-reference has been deprecated

Hello all,

The following code line :

array_push($this->content, &$elt);

produces the following error :

Warning: Call-time pass-by-reference has been deprecated - argument
passed by value; If you would like to pass it by reference, modify the
declaration of array_push(). If you would like to enable call-time
pass-by-reference, you can set allow_call_time_pass_reference to true in
your INI file. However, future versions may not support this any longer.
in /home/sites/site77/web/lib/xml/General_tag.class.php on line 56

What is the propest way to fix it ?

Thx, Thierry.

PS 1 : I can not modify the "online" php.ini file. I'm using PHP v4.1.2
online, and v4.2.0 on local for my tests.

PS 2 : Here is the complete source code.

<?php

/**
* General_tag
*/

class General_tag
{
var $id = "";
var $tag_name = "noname";
var $attributes = array();
var $content = array();

function get_id()
{
return $this->id;
}

function set_id($id)
{
$this->id = $id;
}

function get_tag_name()
{
return $this->tag_name;
}

function set_tag_name($tag_name)
{
$this->tag_name = $tag_name;
}

function &get_attribute_keys()
{
return array_keys($this->attributes);
}

function get_attribute($key)
{
return $this->attributes[$key];
}

function put_attribute($key, $value)
{
$this->attributes[$key] = $value;
}

function is_empty()
{
return count($this->content) == 0;
}

function add(&$elt)
{
array_push($this->content, &$elt);
}

function &get_content()
{
return $this->content;
}

function export(&$result)
{
$this->export_start($result);
$this->export_content($result);
$this->export_end($result);
}

function export_start(&$result)
{
$result .= "<" . $this->get_tag_name();
while (list ($key, $value) = each ($this->attributes))
{
$result .= " " . $key . "=\"" . $value . "\"";
}
$result .= ">";
}

function export_end(&$result)
{
$result .= "</" . $this->get_tag_name() . ">";
}

function export_content(&$result)
{
foreach($this->content as $elt)
{
$elt->export($result);
}
}

function &find_by_id($id)
{
if($this->get_id() == $id)
{
return $this;
}
else
{
$content = &$this->get_content();
foreach(array_keys($content) as $key)
{
$elt = &$content[$key];
$result = &$elt->find_by_id($id);
if($result != null)
{
return $result;
}
}

return null;
}
}

function remove_content_by_id($id)
{
$save_content = $this->get_content();
$this->content = array();
foreach(array_keys($save_content) as $key)
{
$elt = &$save_content[$key];
if($id != "all" && $elt->get_id() != $id )
{
$this->add($elt);
}
}

}
}

?>

Jul 17 '05 #1
3 25066
Carved in mystic runes upon the very living rock, the last words of
Thierry of comp.lang.php make plain:
Hello all,

The following code line :

array_push($this->content, &$elt);


Why would you want to do this? $elt is simply pushed onto the array; it
isn't modified in any way. Why are you trying to pass it by reference?

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
Jul 17 '05 #2
The following code line :

array_push($this->content, &$elt);

Why would you want to do this? $elt is simply pushed onto the array; it
isn't modified in any way. Why are you trying to pass it by reference?


Because I use to do that :

$my_tag = &new General_tag();
$my_tag->set_tag_name("toto");

$my_tag2 = &new General_tag();
$my_tag2->set-tag_name("toto 2");

// Here I use it
$my_tag->add($my_tag2);

// Here it becomes important to have the reference.
// In general, done in an other function.
$my_tag2->set_tag_name("toto 3");

with only array_push($this->content, $elt), the final tag_name of
my_tag2 is still "toto 2"...


Jul 17 '05 #3
Thierry wrote:
The following code line :

array_push($this->content, &$elt);


Why would you want to do this? $elt is simply pushed onto the array;
it isn't modified in any way. Why are you trying to pass it by reference?


Because I use to do that :

$my_tag = &new General_tag();
$my_tag->set_tag_name("toto");

$my_tag2 = &new General_tag();
$my_tag2->set-tag_name("toto 2");

// Here I use it
$my_tag->add($my_tag2);

// Here it becomes important to have the reference.
// In general, done in an other function.
$my_tag2->set_tag_name("toto 3");

with only array_push($this->content, $elt), the final tag_name of
my_tag2 is still "toto 2"...


To get around the call-time reference passing issue, simply create a
function that will do what you want. For instance, something like this
may work for your purposes:

function array_push_ref(&$target,&$value_array){
if(!is_array($target)){
echo 'ERROR: Target is not an array in function array_push_ref.';
return FALSE;
}
if(is_array($value_array)){
foreach($value_array as $val)
$target[]=$val
}
}else{
echo 'WARNING: Passed value is not an array, treating as single
value.';
$target[]=$value_array;
}
return TRUE;
}
--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Marwan | last post by:
Hello I am using asynchronous delegates to make a call to a COM ActiveX object, but even though the call occurs on a separate thread, my UI is still blocking. If i put the thread to sleep in my...
23
by: Fabian Müller | last post by:
Hi all, my question is as follows: If have a class X and a class Y derived from X. Constructor of X is X(param1, param2) . Constructor of Y is Y(param1, ..., param4) .
8
by: trying_to_learn | last post by:
Why do we need to explicitly call the copy constructor and the operator = , for base class and member objects in composition? ....book says "You must explicitly call the GameBoard copy-constructor...
3
by: JoeK | last post by:
Hey all, I am automating a web page from Visual Foxpro. I can control all the textboxes, radio buttons, and command buttons using syntax such as: ...
7
by: rahul8143 | last post by:
hello, what is difference between system call and library function call? Does library function call can have context switch to kernel mode? regards, rahul
5
by: Amaryllis | last post by:
I'm trying to call a CL which is located on our AS400 from a Windows application. I've tried to code it in different ways, but I seem to get the same error every time. Does anyone have any clue...
1
by: news.onet.pl | last post by:
Hello! I have a small question concerning to the procedure call. I have the following procedure: private sub procedure_name (ByVal name1 as string) .... end sub When I call it I just...
3
by: harborboy76 | last post by:
I am calling the exact same stored procedure called myprocedure from 2 different boxes from the CLP, but I'm experiencing different behaviors between them. After I was unable to get any support...
46
by: Steven T. Hatton | last post by:
I just read §2.11.3 of D&E, and I have to say, I'm quite puzzled by what it says. http://java.sun.com/docs/books/tutorial/essential/concurrency/syncrgb.html <shrug> -- NOUN:1. Money or...
3
by: cberthu | last post by:
Hi all, Is it possible to have two connects in the same rexx script to different DB's? I have to get data form on DB (with specifics selects and filter out some values with RExx) and save the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.