216 reputation
18
bio website
location
age
visits member for 2 years, 4 months
seen Jul 27 at 21:08

Jul
27
comment Does it make sense to break fluid interface if a bad argument is passed?
@JamesBlack during development, I kind of like having fatal errors that force me to fix bugs immediately. Perhaps when it is ready for customer use, I change the code so that it throws exceptions for the developer, and the customers/users don't see anything weird. ?
Jul
27
comment Does it make sense to break fluid interface if a bad argument is passed?
The more code I write the more I realize that it is a pain to have a method return different types. But I don't mind PHP fatal errors like false->set('number',12) because they show me where there is an unhandled condition in the code. I can use exceptions to do that without breaking the code, but in a way I prefer the code breaks completely than continues running with unplanned for conditions.
Jun
8
comment Do objects maintain identity under all non-cloning conditions in PHP?
Are you sure about that? I just found this stackoverflow question whose chosen answer states that you do not need to use & with objects. I suppose that fairly soon I will find out for myself once my code is wired and I start testing it. SO: stackoverflow.com/questions/2715026/…
May
15
comment Many-to-many in OOP: Class A instantiates Class B, which instantiates Class A, which
I'm thinking perhaps my third-party would use the "builder pattern." I guess I'll not have the circular dependencies in the constructor. The builder will (somehow?) know which objects to create and then throw them together. Voila. I'm new to design patterns. But my application is getting too complex for me to just keep hacking away at it without a grander scheme.
May
15
comment Many-to-many in OOP: Class A instantiates Class B, which instantiates Class A, which
@teresko I have a mysql database. I have to access it somehow, right?
Apr
27
comment Dependency injection for request variables in a web application
You have to put $_GET['id'] somewhere, though. Should it be outside of all classes, in a functional area of the code? Or should there be a class whose sole purpose is to take globals into itself and instantiate objects of other classes based on them?
Feb
22
comment Is it bad habit not using interfaces?
I enjoyed reading the quoted section, as well as what came before it.
Feb
22
comment Does it make sense to break fluid interface if a bad argument is passed?
I'm just thinking about the advantages/disadvantages. When you stop program execution you know for sure there's been an error without a doubt. But if I return $this no matter whether there was an error or not, then things keep rolling.
Nov
4
comment How can a collection class instantiate many objects with one database call?
I was using a lot of static methods for loading multiple objects. You don't have to use public setters. You can do one database call and load thousands of objects. If I use an object.loadFromDB(), then I have to call it on each one. The OOP solution would seem to be a collection class whose loadFromDB() method would achieve the same result. But then I have to make the setters of the base class public to everyone!
Nov
4
comment How can a collection class instantiate many objects with one database call?
The constructor is public, taking an integer $id to load the object from the db. I think the core of my problem is that I want to load multiple objects with one db query. I need something that can get the data, then instantiate a bunch of the target object. But how can I give a class that power without making methods public to every class?
Nov
4
comment How can a collection class instantiate many objects with one database call?
I'm experimenting with different methods of loading and right now I have several co-existing. All of my properties are non-public, but many classes have public get/set. Sometimes I havec onstructors that take a db id for existing data and 0/null to create new. Sometimes I have a static method that can save multiple data entities at once. Sometimes I have an object save() method. This is all still pretty new to me.
Aug
24
comment Is it good/safe OOP practice to have a method whose only purpose is to send/retrieve data from another class?
Indeed I have run into problems due to my early use of table names. Are you recommending that I pass objects as parameters to other objects' methods, rather than strings/numbers? The "client" object could then use the parameter-object's methods to manipulate it or get data out of it?
Aug
24
comment Is it good/safe OOP practice to have a method whose only purpose is to send/retrieve data from another class?
Hi, sorry for the late reply. The removeWhitespace function in my example would go through a database table and remove the whitespace from every single column. I'm not sure if it would actually make sense for it to be in a utility class, which might have to work on plain strings, database tables, and database columns. What do you think?
Aug
23
comment What are the advantages/disadvantages of using objects as parameters to other object methods?
So your distinction is between whether the instance uses the data/functions of an object of any class, or always of an object of a certain class?
Jan
30
comment Is it a basic principle, or highly desirable, to have class methods that return “$this” rather than a value?
I understand Returning $this returns an instance of the object that the method is a member of. And in PHP OOP I believe, as I said in my question and you say in your answer, that the instance it returns is actually the very same instance as it is... i.e. it returns not a copy of itself but itself. If I am understanding correctly.
Oct
23
comment “Never do in code what you can get the SQL server to do well for you” - Is this a recipe for a bad design?
@skynorth If you rely on the code to make sure your keys maintain integrity, then you are removing a fundamental principle of RDBMS from the DB. That makes no sense, because then every application that accesses the DB will have to make sure to precisely replicate that functionality. Why not just let the DB handle that, since that's what it's designed for. The DB can prevent duplicate keys natively, for example.
Aug
29
comment Why don't inherited methods use child properties? (PHP)
@NickC and who said anything about "coding only with static"? My question has one static function that returns an array of objects that each have object properties. My real class has a lot more class properties and a few more static properties. The question specifically asks about static property behavior, and so I didn't include all the irrelevant class components.
Aug
19
comment Why don't inherited methods use child properties? (PHP)
@NickC then how to handle properties that should remain constant through all objects of a class but allow them to be overridden by child classes? Class constants? Is it <i>better</i> to use a factory construct rather than a static method to generate collections of objects? It seems like the static method is simpler, but I'm probably wrong.
Aug
19
comment Why don't inherited methods use child properties? (PHP)
Why is a static member not OOP? What is it's purpose, then? The data table is a constant for all objects of the class. I guess I could just use a class constant? Also, why is my question voted down 3 times without any explanation? I guess this site doesn't appreciate new posters. Good luck with that.
Aug
19
comment Why don't inherited methods use child properties? (PHP)
Yes that is a typo but it won't let me edit my post while there is an edit pending. And it also won't let me accept the edit. Makes sense, right?