473,804 Members | 3,739 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Call-time pass-by-reference has been deprecated

Hello all,

The following code line :

array_push($thi s->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.cla ss.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($t ag_name)
{
$this->tag_name = $tag_name;
}

function &get_attribute_ keys()
{
return array_keys($thi s->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($thi s->content, &$elt);
}

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

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

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

function export_end(&$re sult)
{
$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_k eys($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_k eys($save_conte nt) as $key)
{
$elt = &$save_conte nt[$key];
if($id != "all" && $elt->get_id() != $id )
{
$this->add($elt);
}
}

}
}

?>

Jul 17 '05 #1
3 25090
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($thi s->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($t his->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($thi s->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($thi s->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($thi s->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,&$valu e_array){
if(!is_array($t arget)){
echo 'ERROR: Target is not an array in function array_push_ref. ';
return FALSE;
}
if(is_array($va lue_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
3405
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 delegate call, the application is well behaved (no UI freeze), but the call to the com object causes the UI to lock up Do I have to manage calls to an ActiveX object differently than using the BeginInvoke and a callback A sample of the code I...
23
5186
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
2986
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 or the default constructor is automatically called instead" Why cant the compiler do this on its own. if we are making an object through copr construction for an inherited class , then why not simply call the corresponding copy constructors for...
3
4063
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: oIE.Document.Forms("searchform").Item(<name>).Value = <myvalue> But I cannot control a dropdown with an onchange event. I can set the dropdown's value and selectedIndex, but then calling the onChange() or Click() does not do anything. It only seems to fire the onchange if I
7
6956
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
3782
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 as to what this means? I am not trying to alter a table. This particular CL merely generates the next voucher number in a sequence. "SQL0204: HRCU030P in HRZNCUSOBJ type *N not found. Cause . . . . . : HRCU030P in HRZNCUSOBJ type *N was...
1
1703
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 write:
3
4326
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 from IBM due to V7.1 being no longer supported, I figure someone here might be able to help. Is DB2 V7 more forgiving in the way I can call my stored procedure ? If it's defined with CHARACTER as incoming parameter, am I not required to put any...
46
3866
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 property bequeathed to another by will. 2. Something handed down from an ancestor or a predecessor or from the past: a legacy of religious freedom. ETYMOLOGY: MidE legacie, office of a deputy, from OF, from ML legatia, from L legare, to depute, bequeath....
3
4788
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 results into another DB? I know from Wscripts and MS-Sql that you can build just two objects but I did not see something like that in REXX. Thanks in advance for your help
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9582
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10580
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10335
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10082
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6854
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3821
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2993
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.