Portal Home > Knowledgebase > Articles Database > What is the different type of variabel in Php?
What is the different type of variabel in Php?
Posted by Aayus, 07-23-2012, 07:58 AM |
I'm the beginner in this language and want to know about the different type of variable are used in PHP.
|
Posted by SajanP, 07-23-2012, 08:06 AM |
If you're asking about data types, here's a list of different things that can be stored in php variables.
http://php.net/manual/en/language.types.php
PHP is nice in the fact that you don't have to declare what type a variable is, nor is a variable limited to just one type. You can have a variable store a string in the beginning of a script, then later use it to store an array. All without having to really tell or warn php about it unlike in languages like Java.
|
Posted by nehir, 07-23-2012, 08:31 AM |
|
Posted by File1eu, 07-23-2012, 09:30 AM |
Declare and initialize a variable
Use a variable inside another variable
You can only use a variable inside double quotes, this does not work
Show the referer, i.e. where the user comes from if the browser sets it. Note the curly brackets around array variables.
Really, everything else you need to know is in the manual.
|
Posted by nehir, 07-23-2012, 09:52 AM |
even better...
|
Posted by StadenHosting, 07-23-2012, 11:00 AM |
This page has more information on PHP variables.
http://www.w3schools.com/php/php_variables.asp
PHP Variable Scope
The scope of a variable is the portion of the script in which the variable can be referenced.
PHP has four different variable scopes:
local
global
static
parameter
|
Posted by Hire Developer, 07-24-2012, 03:27 AM |
Well, there plenty of variables in PHP which you can see from this link http://www.tutorialspoint.com/php/ph...able_types.htm. Hopefully it will clear your confusion.
|
Posted by teamhostersbill, 07-24-2012, 06:34 AM |
u may be comparing php with c or c++...
Php variables start with $ sign
It can hold any type of data...
No need to declare variables with datatypes
|
Posted by streaky, 07-24-2012, 07:50 PM |
Yeah nice XSS attack vector there genius, any more bad ideas you want to share with the new guy?
|
Posted by nehir, 07-25-2012, 04:51 AM |
He just posted an example, the new guy should learn basic steps at the beginning then security...
btw I've already posted a better version..
Note: You can XSS attack yourself only (With above code)
|
Posted by stanpetkov, 08-08-2012, 12:33 PM |
the type is determined by the value:
- integer - 1,2,3,4,5....
- floating-point - 1,15...
- boolean - true or false
- string - "some text..."
$prom - true
$prom1 - true
$prom-1 - false
|
Posted by File1eu, 08-09-2012, 05:02 AM |
Yes, it's not really harmful but of course, whenever you output user input, use somtething like:
@streaky: good luck XXS-ing yourself...
|
Posted by zoid, 08-09-2012, 05:56 AM |
If you are already brave enough to criticise others you should be also kind and exact enough to mention that the code you quoted is in fact no XSS attack as a potential attacker would only attack himself.
It only becomes an issue when user-supplied data is displayed to third parties.
|
Posted by phpdevelopment, 08-13-2012, 04:29 AM |
Here are the most important things to know about variables in PHP.
All variables in PHP are denoted with a leading dollar sign ($). The value of a variable is the value of its most recent assignment. Variables are assigned with the = operator, with the variable on the left-hand side and the expression to be evaluated on the right. Variables can, but do not need, to be declared before assignment. Variables in PHP do not have intrinsic types - a variable does not know in advance whether it will be used to store a number or a string of characters. Variables used before they are assigned have default values. PHP does a good job of automatically converting types from one to another when necessary. PHP variables are Perl-like.
|
Posted by dubdub, 08-14-2012, 05:38 AM |
Not true at all!
Maybe if you have turned off error_reporting you think this is true..
|
Posted by lynxus, 08-14-2012, 05:42 AM |
Id recommend you follow this:
http://www.tizag.com/phpT/
It will take a few hours to work through (Can be done in a day)
And once you have finished you will have a great starting ground for PHP.
|
Posted by applehost, 08-15-2012, 09:39 AM |
Since PHP isn't typed, a variable is a variable. $variable = 'one' is, of course, a string, but $variable = 1 can be string or integer (or floating point). PHP doesn't care. If the variable can't be used in the construct (raising a string to a power, for instance), you'll get an error, but if it can be done it will be done (even if that's not what you meant - so you have to be careful how you define things).
See http://www.php.net/manual/en/languag...e-juggling.php for how PHP changes types as needed.
|
Posted by scottF, 08-15-2012, 08:01 PM |
The normal / available arrays:
var_dump($_SERVER);
var_dump($_REQUEST); //GET AND POST
var_dump($_GET);
var_dump($_POST);
?>
(absolute guess, given no clarification from original poster)
|
Posted by Aayus, 08-18-2012, 02:55 AM |
How can i compare it with C and C++. if you have idea to do this, provide it.
|
Posted by css4me, 10-09-2012, 07:27 AM |
There are eight type of data types:
Integers
Doubles
Booleans
NULL
Strings
Arrays
Objects
Resources
|
Add to Favourites Print this Article
Also Read