answersLogoWhite

0

Use the "static" keyword to declare a static variable within a function like shown below.

<?php

function fun() {

static $variable;

static $another_variable = '';

}

?>

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

What is static language?

A static language is a programming language in which variables must be declared with their specific data types before they can be used. This allows for type checking to be performed at compile-time, catching potential errors before the program is executed. Examples of static languages include C, C++, Java, and C#.


What is the disadvantage of using PHP?

As far as I know.. the only bad issue I see as a PHP developer is that you don't have the variables/attributes type. I mean you can set an integer attribute then set the same attribute as string. And I just discovered that if you use a non-static method as static, the php accepts it as if it was normal... =P The advantage of using php is that you may develop your systems faster and easily. Regards.. Gabriel Rocha


Are static variables serialized in java?

No, static variables are not serialized.


Why is PHP used?

PHP is used to create dynamic websites, this is a step up from HTML as it allows you to do much more than creating static websites. Using a language such as PHP also gives you access to using databases with your website such as MySQL.


Why you say that no static binding in php?

PHP supports late static binding since version 5.3, which was officially released in June of 2009.


What is a preprocessor in PHP?

As it is, PHP does not have a preprocessor; it is a preprocessor that processes form variables and other environmental variables and prints HTML or general text.


How can a PHP static be initialized?

PHP static can only be initialized using a literal or constant. You can not use an expression. You can initialize it to an integer but you may not to another variable.


Why static functions cannot use instant variables?

Static functions are tied to a class, not to a particular object. A static function can only access static variables because it has no knowledge of member variables.


It is perfectly legal to any instance variable inside of a static method?

No. You will get compilation errors. The complier will complain that you are trying to access non static variables from inside a static method. A static method can access only static variables.


How do you access the static variable and static methods of a class?

In java we access static variables and static methods without creating objects. i.e.,we can access directly by using classname we can also access static variables and static methods by using objects which are created by using class where the static variables and static methods are available


Can variables be changed?

A static variable is one which is not stored on the stack but in the memory of the program. Static variables can be changed.


Why memory is divided into initialized and uninitialized areas?

The program's data segment. This area of memory is allocated by the linker and is used to store the program's global variables, static variables, static arrays and constants. Constants are always initialised, as are static variables, but global variables and static arrays need not be initialised.


Can non static methods can access static variables?

Yes, they can


All variables in PHP start with which symbol?

In PHP, all variables must the preceded by the dollar sign. Variable name must not contain any space as well.


Is it possible to write in static variables in main method in java?

Short answer: No. Only class member variables may be declared static. Local variables with a static declaration will throw an error (usually "illegal start of expression").


Are static variable created by giving keyword static in java?

yes bcoz static variables


How do you install crystal reports for php?

how to create report in php


Where the static variables are stored?

initialize static variables are stored in data segment where uninitialized static variables are stored in BSS(block storing for Symbol) it also a part of data segment exp static int i=10;//stored in data segment static int i;//stored in BSS (uninitialized data segment) Thanks NAvin


Can a static method access instance variables?

Variables cannot access variables; only methods can access variables. Non-static methods (also known as instance methods) are local to an object of the class and therefore have access to a "this" reference (referring to the current instance of the class, the object upon which the method was invoked), but static variables are local to the class itself. These variables are shared by all objects of the class and are therefore accessible to non-static methods. Static variable are also accessible to static methods and are therefore accessible even when no objects of the class exist.


Are C variables initialized to 0 by default?

Only global/static variables are, local variables aren't.