Welcome Guest, Not a member yet? Register   Sign In
Problem between using a Model or using a Library
#11

[eluser]wiredesignz[/eluser]
If your first model contains the methods and variables common to all the other inherited models, no you aren't wasting resources. Quite the opposite. PHP5 uses a reference to the original and also if you use an ampersand in PHP4.
#12

[eluser]BizComputing[/eluser]
Yes you are wasting resources, those variables that are instance variables will be instantiated on CI's load model. If you have no intention of using the model loaded via CI, then the space consumed by the loaded instance variables is a waste as well as the reference stored in your controller.

If you are in PHP 5, you do also have the ability to extend the loader class and add your model data as an argument to your extended model loading.
#13

[eluser]wiredesignz[/eluser]
Not true, Read this from PHP.net:

Quote: When assigning an already created instance of a class to a new variable, the new variable will access the same instance as the object that was assigned.

http://nz.php.net/manual/en/language.oop5.basic.php
#14

[eluser]BizComputing[/eluser]
Seems today wired we are not seeing eye to eye.

So, with your example above,

$this->load->model('Model_name');

$cat = new Model_name($cat_features);
$dog = new Model_name($dog_features);
$rat = new Model_name($rat_features);

cat is the same as dog is the same as rat is the same as the base model that was loaded via load. If they all share the same data, then they are all the same. Seems to me that the purpose of an instance is to allow differences in data and therefore that data cannot be shared. How can a cat be a cat if it shares the same variable as a dog for species?
#15

[eluser]wiredesignz[/eluser]
The class variables of each instance are empty until you use then and the methods are referenced to the parent.

EDIT: However, I have it from a reliable source that the instances are not shared but duplicated, so yes, the first object is wasted memory in this case.
#16

[eluser]section31[/eluser]
The object itself takes up memory, not only the class variables.




Theme © iAndrew 2016 - Forum software by © MyBB