Questions tagged [unset]

Removing the value associated with a variable or property from the current environment.

Common usages:

  • Destroying a variable or member of an array in PHP.
  • Removing the value bound to a property in Apache Ant.
  • Removing a variable from the environment of a shell script.
595 questions
3
votes
4 answers

Destroy session, but keep one variable set

I am using session variables to control logins and page access. I use variables to control different user groups that a user belongs to, so I have quite a few session variables. I also use a session variable to remember the users last visited page…
Eds
  • 533
  • 4
  • 16
  • 35
3
votes
2 answers

How is it possible to access an object's property after it has been destroyed/unset (__destruct() executed)?

TL;DR > echo (new ClassName())->propertyName; Will call the __destruct(), run its code and AFTER THAT successfully retrieve its "propertyName" property (which will be echoed normally). How can it be retrieving a property from a "destroyed" (or…
3
votes
5 answers

Unsetting empty array elements

I'm working with $_FILES and sometimes the array has empty array elements due to empty file inputs on my form. I'm trying to unset these elements. I've tried these code snippets: foreach($_FILES['images']['name'] as $image) { if(empty($image)) …
John
  • 187
  • 1
  • 7
3
votes
0 answers

Visual Studio Code PHP Intelephense not hilight probably unset variables

Visual Studio Code PHP Intelephense not hilight probably unset varuables. How enable hilight probably unset varuables? PhpStorm do it. Code: foreach ($paymentCollection as $payment) { if (!$payment->isInner() &&…
3
votes
3 answers

View generation and reserved names in PHP

This is a bit of a peculiar one; I don't think this is in fact possible, however the SO community has surprised me time and time again; so here goes. Given in PHP; I have the following snippet: $path = 'path/to/file.php'; $buffer =…
Dan Lugg
  • 20,192
  • 19
  • 110
  • 174
3
votes
1 answer

Remove countries in WooCommerce from an array of defined country codes

I found How to remove specific country in WooCommerce answer code that works for unsetting one country. How can I use it to unset more countries 3-4? This code works to hide US from my geolocation list. I need it to hide a few more countries based…
Radu
  • 45
  • 7
3
votes
0 answers

Is it possible to unset a static property in PHP?

I'm trying to use classes with static methods and properties instead of Singletons. Everything was ok until I had to unset a static property, and my PHP 8.0 threw an error. I need this because the property may not be set at some point, for lazy…
Joan Botella
  • 315
  • 1
  • 2
  • 14
3
votes
3 answers

Questions about php unset function

I am having questions about unset How to unset all variables.should i use unset($var1,$var2,$var3,...) or any other easy method exists ? unseting the variables at the end of functions is good practice?.any difference ! unseting the variable is…
Gowri
  • 16,587
  • 26
  • 100
  • 160
3
votes
5 answers

PHP memory question do you need to unset?

What happens if you do not unset an array before the script is done executing? I am running through thousands of CSV files, parsing data for hundreds of thousands of customers into arrays. It works fine for the first 5/6 hours then starts bogging…
Mark
  • 31
  • 3
3
votes
2 answers

Using eval() in the code, and how would you avoid it?

In my code, I want to try fetching $_POST or $_GET variables, and unsetting them as soon as they were requested once. This function returns the method used, which is simple enough. Unfortunately I cannot simply return the $_POST or $_GET variables…
Dwarf Vader
  • 429
  • 1
  • 5
  • 14
3
votes
1 answer

can't drag element that has css property unset: all

It seems I'm not able to drag an element that has unset: all css property. .my-component { all: initial; * { all: unset; } } I use these rules inside a chrome extension, on elements that are being injected in the user browser page (to…
3
votes
2 answers

PHP - Is there a way to get a variable value if it is set?

I always find myself writing something like: if(isset($var)) { DoSomethingWith($var); } else { DoSomethingWith(null); } or if(isset($arr["key"])) { DoSomethingWith($arr["key"]; } else { DoSomethingWith(null); } My question is…
J. Brown
  • 124
  • 7
3
votes
3 answers

how do i unset multiple keys in php

I am getting error while unset the data. Can anyone tell me how to do that. Here i have column array look like:- enter code here Array ( [0] => Id [1] => Name [2] => MainDeity [3] => Description [4] => MainImage [5] => Category [6] => Tehsil [7] =>…
user6384346
3
votes
1 answer

unset object inside an array of objects

I have a problem with remove items from an array with object, the same code run in other app. After looping the array $categories should be empty. The code bellow removes all children categories then removes the parent category if the user pass the…
owis sabry
  • 154
  • 9
3
votes
2 answers

Reduce an array of objects to the 'best 10'

I have an array of objects, which are Soccer players. The array can contain anything from zero to thousands of players. I want to reduce it to the best 10. My initial attempt was as follows : while (count($ArrayOfPlayers) > 10) { $ArrayIndex =…
Farflame
  • 421
  • 1
  • 5
  • 17