473,785 Members | 2,798 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

References and unset

Airslash
221 New Member
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(SqlPqrqm eter &$parameter) {
# check if the variable is in the array
# done by reference to prevent overhead copies
foreach($this->commandparamet ers as &$param) {
if($param->equals($parame ter)) {
unset($param);
}
}
# break the reference
unset($param);
# restore the array
$this->commandparamet ers = array_values($t his->commandparamet ers);
}
[/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(SqlPqrqm eter &$parameter) {
# check if the variable is in the array
# done by reference to prevent overhead copies
foreach($this->commandparamet ers as $key=>&$value) {
if($value->equals($parame ter)) {
# delete the parameter form the internal array
unset($this->commandparamet ers[$key]);
}
}
# break the reference
unset($param);
# restore the array
$this->commandparamet ers = array_values($t his->commandparamet ers);
}
[/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 1417

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

Similar topics

4
2123
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, in which case it gets a reference out of the array and returns that, again by reference? I'm getting out of memory error, meaning my scrip is using the 8 megs that PHP scripts are, by default, allowed. So I'm left to think I've done something...
7
2132
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 file? unset($fp); Can I use unset to kill a pointer to a database return? unset($mySqlResult);
3
14906
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 after unset() is called. Is there some special setting in PHP that can allow a session to
2
2015
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 in the process that creates the reference when it is being assigned to an array element within itself. If it is already referenced, it just assigns the existing reference and avoids the problem.
21
3394
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 function. DO: $var = null; DONT DO: unset($var);
3
4115
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 will discard the variable alltogether... if ($categoryid == "all") { $sql = "SELECT * FROM products where shopinspection=$shopinspection"; unset($HTTP_POST_VARS); unset($HTTP_POST_VARS);
1
1892
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
1861
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 will discard the variable alltogether... if ($categoryid == "all") { $sql = "SELECT * FROM products where shopinspection=$shopinspection"; unset($HTTP_POST_VARS); unset($HTTP_POST_VARS);
5
2298
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) || @sizeof($leaseObj->errorArray) == 0)) { print_r(array_keys($_POST)); @reset($_POST); $tempPost = $_POST; foreach ($_POST as $key =$val) if (strpos($key, 'new_') === 0) array_remove($tempPost, $tempPost);
0
9645
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
9481
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
10336
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...
1
10095
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7502
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6741
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();...
0
5383
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
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

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.