isset

Why is array_key_exists 1000x slower than isset on referenced arrays?

ε祈祈猫儿з 提交于 2019-12-18 14:03:35
问题 I have found that array_key_exists is over 1000x slower than isset at check if a key is set in an array reference. Does anyone that has an understanding of how PHP is implemented explain why this is true? EDIT: I've added another case that seems to point to it being overhead required in calling functions with a reference. Benchmark Example function isset_( $key, array $array ) { return isset( $array[$key] ); } $my_array = array(); $start = microtime( TRUE ); for( $i = 1; $i < 10000; $i++ ) {

XCTF-ics-07

安稳与你 提交于 2019-12-18 04:26:26
题目描述:工控云管理系统项目管理页面解析漏洞 打开题目网址,点击项目管理 进来之后,发现页面下方有一个view-source 点击之后得到页面源码 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>cetc7</title> </head> <body> <?php session_start(); if (!isset($_GET[page])) { show_source(__FILE__); die(); } if (isset($_GET[page]) && $_GET[page] != 'index.php') { include('flag.php'); }else { header('Location: ?page=flag.php'); } ?> <form action="#" method="get"> page : <input type="text" name="page" value=""> id : <input type="text" name="id" value=""> <input type="submit" name="submit" value="submit"> </form> <br /> <a href="index.phps">view-source</a> <

PHP - Checking if array index exist or is null

那年仲夏 提交于 2019-12-18 03:10:24
问题 Is there a way to check if an array index exists or is null ? isset() doesn't tell you whether the index doesn't exist or exists but is null. If I do : isset($array[$index]) || is_null($array[$index]) it won't work because if the index doesn't exist is_null will crash. How can I check this please? Also is there a way to check only if something exist, no matter if it is set to null or not? 回答1: The function array_key_exists() can do that, and property_exists() for objects, plus what Vineet1982

PHP: Check if variable exist but also if has a value equal to something

时光怂恿深爱的人放手 提交于 2019-12-17 16:02:55
问题 I have (or not) a variable $_GET['myvar'] coming from my query string and I want to check if this variable exists and also if the value corresponds to something inside my if statement: What I'm doing and think is not the best way to do: if(isset($_GET['myvar']) && $_GET['myvar'] == 'something') : do something My question is, exist any way to do this without declare the variable twice? That is a simple case but imagine have to compare many of this $myvar variables. 回答1: Sadly that's the only

Test if an argument of a function is set or not in R

北城以北 提交于 2019-12-17 15:34:48
问题 I have a function f that takes two parameters ( p1 and p2 ): If for the parameter p2 no value was passed to the function, the value of p1 ^2 should be used instead. But how can I find out within the function, if a value is given or not. The problem is that the variable p2 is not initialized if there was no value. Thus I can't test for p2 being NULL . f <- function(p1, p2) { if(is.null(p2)) { p2=p1^2 } p1-p2 } Is it somehow possible to check if a value for p2 was passed to the function or not?

What is the difference between null and empty?

大城市里の小女人 提交于 2019-12-17 10:31:15
问题 I am new to the concept of empty and null. Whilst I have endeavoured to understand the difference between them, I am more confused. I came across an article at http://www.tutorialarena.com/blog/php-isset-vs-empty.php however I still don't see when you would use isset and empty when validating forms. Seeing that I don't grasp the difference, I don't want to be using the incorrect functions as well as not be able to use the functions in other areas. Can someone give examples that will help me

What is the PHP shorthand for: print var if var exist

一个人想着一个人 提交于 2019-12-17 07:26:54
问题 We've all encountered it before, needing to print a variable in an input field but not knowing for sure whether the var is set, like this. Basically this is to avoid an e_warning. <input value='<?php if(isset($var)){print($var);}; ?>'> How can I write this shorter? I'm okay introducing a new function like this: <input value='<?php printvar('myvar'); ?>'> But I don't succeed in writing the printvar() function. 回答1: For PHP >= 5.x: My recommendation would be to create a issetor function:

What is the PHP shorthand for: print var if var exist

◇◆丶佛笑我妖孽 提交于 2019-12-17 07:26:52
问题 We've all encountered it before, needing to print a variable in an input field but not knowing for sure whether the var is set, like this. Basically this is to avoid an e_warning. <input value='<?php if(isset($var)){print($var);}; ?>'> How can I write this shorter? I'm okay introducing a new function like this: <input value='<?php printvar('myvar'); ?>'> But I don't succeed in writing the printvar() function. 回答1: For PHP >= 5.x: My recommendation would be to create a issetor function:

Check if value isset and null

為{幸葍}努か 提交于 2019-12-17 07:15:36
问题 I need to check if value is defined as anything, including null. isset treats null values as undefined and returns false . Take the following as an example: $foo = null; if(isset($foo)) // returns false if(isset($bar)) // returns false if(isset($foo) || is_null($foo)) // returns true if(isset($bar) || is_null($bar)) // returns true, raises a notice Note that $bar is undefined. I need to find a condition that satisfies the following: if(something($bar)) // returns false; if(something($foo)) //

In where shall I use isset() and !empty()

跟風遠走 提交于 2019-12-17 03:01:58
问题 I read somewhere that the isset() function treats an empty string as TRUE , therefore isset() is not an effective way to validate text inputs and text boxes from a HTML form. So you can use empty() to check that a user typed something. Is it true that the isset() function treats an empty string as TRUE ? Then in which situations should I use isset() ? Should I always use !empty() to check if there is something? For example instead of if(isset($_GET['gender']))... Using this if(!empty($_GET[