473,404 Members | 2,174 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,404 software developers and data experts.

References and unset

Airslash
221 100+
Hello,

I've written a small function to delete a variable from a class' internal array.
The variables on their own are custom class objects, and I'm a bit confused about the whole pass by reference thing.

First I'll show you the code:

[PHP]
# removes a parameter from the array.
# variables are passed as reference to prevent overhead.
public function delVar(SqlPqrqmeter &$parameter) {
# check if the variable is in the array
# done by reference to prevent overhead copies
foreach($this->commandparameters as &$param) {
if($param->equals($parameter)) {
unset($param);
}
}
# break the reference
unset($param);
# restore the array
$this->commandparameters = array_values($this->commandparameters);
}
[/PHP]

I'm confused about the unset part.I know I need to call unset on my $param value after the foreach loop to break the reference with the internal array, But I wish to destroy the variable thats holding the position inside the array is it matches the value of the provided parameter.

Am I using the unset function correctly there or should I do it differently ?

EDIT
-------

Changed the code into this :

[PHP]
# removes a parameter from the array.
# variables are passed as reference to prevent overhead.
public function delVar(SqlPqrqmeter &$parameter) {
# check if the variable is in the array
# done by reference to prevent overhead copies
foreach($this->commandparameters as $key=>&$value) {
if($value->equals($parameter)) {
# delete the parameter form the internal array
unset($this->commandparameters[$key]);
}
}
# break the reference
unset($param);
# restore the array
$this->commandparameters = array_values($this->commandparameters);
}
[/PHP]

I don't know if this is THE solution to my problem, but it makes more sense to me now.
Nov 19 '08 #1
0 1388

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: lawrence | last post by:
I'm nervous this method is not doing what I assumed it was doing. Does it not create objects, store them in an array, and check that array to see if a requested class has already been instantiated,...
7
by: lawrence | last post by:
Given a bunch of mixes variables, I'm in a situation where I can't know what type they are. Can I use unset to kill an object? unset($object); Can I use unset to kill a pointer to an open...
3
by: Phil Powell | last post by:
PHP: unset($_SESSION); In my original environment (PHP 4.3.2) this line will delete the session variable 'mainDisplay'. But in the testing environment (PHP 4.3.6) the variable persists even...
2
by: Kaptain524 | last post by:
Hello, I am using PHP 5.0.4 with Apache 2, on WinXP Pro. This behavior appears to be fundamental however, and should not be affected by platform. It would seem that there is some kind of bug...
21
by: steve | last post by:
Dont’ make my mistake. It is costly. Say you have defined a variable $var in your main script. Now in a function you access it using: global $var; But you want to set it to null inside the...
3
by: fasanay | last post by:
Hi everybody I have got the following PHP code which I am trying to convert to ASP any help will be appreciated...I have done most of it but I cant find a replace function for Unset in asp which...
1
by: frizzle | last post by:
Hi group, Why won't $new_var be unset in the following function? Am i missing out something? Greetings Frizzle. *************************************
7
by: fasanay | last post by:
Hi everybody I have got the following PHP code which I am trying to convert to ASP any help will be appreciated...I have done most of it but I cant find a replace function for Unset in asp which...
5
by: comp.lang.php | last post by:
// NEW 11/27/2006: FINALLY, IF YOU ADDED OR DELETED OR DID ANY KIND OF FORM ACTION SUCCESSFULLY, DON'T RE-DISPLAY THE NEW EXPENSE ITEMS VIA $_POST if ($_POST && (!is_array($leaseObj->errorArray)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.