How long does the instance variable last? In Rails? In Java? In PHP?

If I create an instance of a class and set an instance variable in the Ruby module used by the controller or Rails model, how long does this instance variable last? Do I need to explicitly save a variable in a session to save between requests?

How do Rails compare in this respect with Java or PHP?

+1
source share
3 answers

In Ruby on Rails, it always depends on the scope and definition.

For example, object / instance variables defined in your environment and configuration files will always be saved. A simple example of this is ActiveMerchant payment gateways, which are defined in the environment.rb file and are present for each request.

HTTP-, .

+1

PHP . , PHP4 , 5.2 5.3: , - (memcached, database, file ..) . PHP ( ).

PHP:

, , . PHP . , PHP refcount 0. 0, .

PHP 5.0, 5.1 5.2:

. , ( A B ), , .

PHP 5.3:

PHP . . , .

+2

He exists only within the limits of his possibilities. If it is global, it will exist as long as the session continues. But if it is not global, it will not exist after you leave the area in which it exists.

+1
source

All Articles