« first day (117 days earlier)    last day (14 days later) » 

07:24
Yes, what you describe sounds good. It is standard, often done, and absolutely fine.
This is exactly what OOP, so object oriented programming is about.
@Sajad: so: go! :-)
 
4 hours later…
11:09
@arkascha ah I see, thanks
but for last time, extending is not slow? if I write all those array in the each class as a separated method is not faster?
anyway, I'm doubt now, one father classes for constant codes, or writing those constant codes in the each class as a method?
I don't know why I scare of "extends". I feel it needs to a lot of process for extending
is it true?
thanks and thanks again ;)
... one father class for ... *
11:25
As said: the difference is next to zero even in theoretical nature.
Apart from that: php caches the compiled code (php is a "just-in-time compiler").
So in practice there is no difference.
(Except for the first ever call of that script)
I suggest you try that out yourself. Make such code and instantiate many objects, say 5 million objects. You take the time for both variants. Then you compare the two results you got.
@Sajad :-)
:-)
alright !
11:41
aslo can I write PDO database connection in the Father class? Because all classes need to database gist.github.com/anonymous/13e5b3fa740dc9526741
Obviously you want to define the setup and initialization of your database connection only once, yes.
I would not place that in one parent class extended in all other classes, I would prefer to put it into a separate class by itself to keep separate things separate. But in the end that is a question of personal preferences.
The advantage of a separate class is that the database connection object will only be instantiated if it is actually required.
separate class just for database connection?! and using include() for adding it in the other classes?
or do I need to another autoloader?
actually I can not imagine how can I access separated (database connection) in other classes
12:44
because if I define separated class for database connection, then I should write these every time I want to use database:
$database_obj = new database();
$dbh = $database_obj->dbh;
 
3 hours later…
15:28
You always use only one single autoloader. Whenever a class is used the autoloader decides which file to load. So this is a question of your naming scheme. You always name the files where classes are defined such, that the autoloader can see where to look for the file based on the name of the class.
About the database connection: this is a bit a question of personal choice. Many patterns exist.
In general two are wide spread:
1. you derive from (extend) the basic database class (mysqli or PDO) to include whatever you need, for example the database credentials
2. you implement a wrapper around the inner database object. The wrapper maintains the inner object (instantiates it and controls its state) and relays all queries.
Both is possible, as said a question of personal taste.
If you currently do not use such a class, then how did you implement your database connection?
 
2 hours later…
17:02
@arkascha do you mean is something like this, right?
17:15
alse here is what I meant
17:31
^ this demo missed this:
public function __construct(){
    parent::dbh();
}
The first link looks a bit like the second variant I mentioned, the wrapper.
You second example tries to combine your "father" class with that approach.
This certainly is possible.
But as said before: I see no reason to do so and I myself would advise against that.
Reason is simply, that separate things should be kept separate, so implemented separate.
Mixing completely different things into one will result in a big thing that is complex and hard to maintain.
yes, you are right.
I will try separately ... tnx :-)
You are welcome :-)
just one thing, how can I use those arrays (in the Father class) in the Child classe?
Since you derive your child classes from that father classes the array are automatically available in the child classes. That is the idea behind class hierarchies. Just access them as if you had implemented them as properties in the current child class.
One design hint: since those arrays hold exactly the same content for all child classes, so for all objects you create from the child classes, it makes sense to declare the arrays as shared properties of the parent class.
That way the arrays get created only once in memory and are shared between all objects.
That makes sense: it saves time and memory.
17:46
thanks for the hint, but please show me it as some code example ... (please)
OK, wait a bit...
because optimizing is really important to me
@arkascha ok, really tnx
Just a side note: you are investing so much time into optimization...
Maybe php is somply the wrong language for you to use?
If you are really concerned with highest performance, then you should use the C language.
I understand what is your mean, because always my friend tell me: "when you (I) speach, we (my friends) fell you are talking about assembly (Low-level programming)"
Well, assembly is rarely used these days...
17:58
yes, it is just for devices
But the power behind C is, that although it is a high level language, it allows to implement code that is nearly as compact and efficient as with assembler.
As said: rarely.
Most firmware is implemented in C these days, not in assembler any more.
Here is an example of what I meant above:
It demonstrates how to implement that catalog ("arrays") as static properties.
Note, that the arrays are not setup inside the constructor, so they are not created multiple times, but only once.
They are "shared".
Obviously this only makes sense if the arrays really are meant as some sort of static configuration.
this is another variant, it is even more common for such static catalogs:
No hierarchy at all, since it is not required for this.
(sorry, I only realized after posting the first example)
As long as the catalog contains only static content, so const and static declared properties and static declared methods, there is no need to instantiate an object at all. You can directly access such static things via the class name. Perfect for configuration stuff.
18:20
I got it ...!
really thanks. this note (using static property) is really good
well done!
Have fun :-)
thanks again and have fun too

« first day (117 days earlier)    last day (14 days later) »