Tag Info

Hot answers tagged

12

I'm going to try to explain this with an example. Lets say you want to build a website that shows people a list of friends. So it starts with a list of your friends (A,B,C..). When you select one, it shows a list of their friends (A1, A2, etc) and so on. The "View" is an implementation of what the user can see. In this case, we need only one view i.e. a ...


10

Model The model represents the domain you are trying to model, and also encapsulates the business logic of your application. For example, using the good old blog example, think about all the things your make up your blog: Posts, Comments, Tags, Categories, Authors, Commentors, Editors, Feeds, etc. This is your domain, and depending on which of those you ...


4

Lua too has this trait. Lua's tables can be treated as both maps and arrays. (Internally, a Lua table is implemented by having two parts (the user isn't aware of this), the array part and the map part, so it's efficient.) (JavaScript has some kind of this duality too: since every object can serve as a map, and every array is an object, arrays can serve as ...


4

The inefficiency/messiness is coming from "hydrating" your data too early and too often. By "hydrating," I mean instantiating data objects from (what I assume are) records in your database. You don't always need to deal with data objects. For example, with this code... $posts = Posts::getPosts(); // get the ids into an array $post_ids = array(); ...


4

You might consider making LoadProducts() a static method, so that you don't have to instantiate a blank object to load a product list: class Product { public static function LoadProducts(...) { } } and then its just $products = Product::LoadProducts( ...)


4

Applications can communicate using an Application Programming Interface (API). When writing a program, the developer can choose to expose certain functions to allow other programs to interact with them. By only exposing certain functions, and in a certain way, the developer allows people to use his application in a safe way without accidentally (or ...


4

The description on the Suhosin website is pretty clear, emphasis mine: If you are using PHP only for your own server and only for your own scripts and applications, then you can judge for yourself, if you trust your code enough. In that case you most probably don’t need the Suhosin extension. [...] Even PHP core programmers are writing insecure code from ...


3

Cloud, put plainly, is a server for rent available online. As such, generally most of the types of hassles regarding setting up a server and making it accessible online while not putting the rest of your network at risk, is already handled for you. There are several types of clouds depending on what the cloud offers you: Storage clouds - They offer a ...


2

"Popular" is in the eye of the beholder. The Rexx language is very popular in the mainframe communities, and it has associative arrays (called "compound variables") as a first-class language element.


2

What you're talking about here is dependency inversion and encapsulation. You consuming code wants to hold a dependency on some means of getting hold of domain entities, without needing to know how that happens. It wants a set of methods on a black box, which it expects to give some inputs and get some outputs: an interface. Instead of having your code ...


2

Since PHP5, __construct is the constructor. It will only use the old way (PHP4) if there is no __construct function. From http://www.php.net/manual/en/language.oop5.decon.php: For backwards compatibility, if PHP 5 cannot find a __construct() function for a given class, and the class did not inherit one from a parent class, it will search for the ...


2

The only solution I would consider for this problem is TAR. If you cannot find a PHP Tar implementation then implementing TAR in PHP saves you the time of designing your own format. Although you are not interested in unarchivers, the fact that every OS of any real consequence has TAR tools means verifying your implementation becomes significantly easier. ...


2

Your original approach does lazy loading while your modified code does eager loading. You are absolutely right that eager loading is more efficient in your situation. In most cases, minimising the number of queries is the best thing you can do to speed up your app. If you were only going to look at one of the posts then lazy loading would be faster. Most ...


2

Unless you are introducing an existing framework into the code and 90% of the original code will be taken over by the framework, doing a big rewrite will almost certainly cost more time than incrementally refactoring the code. If the original code is essentially good (well documented & structured), but just not according to today's best practices, then ...


2

The idea is simply to create a clear separation between business logic and the UI. The Model is the data and the business logic of the application. The View is UI logic, and creates a visual representation of the Model. The Controller is mediating between the two to keep them loosely coupled. Here's an example to help you understand. This relates more to ...


1

I would have to recommend the advice of Martin Fowler on this one. When you find you have to add a feature to a program, and the program's code is not structured in a convenient way to add the feature, first refactor the program to make it easy to add the feature, then add the feature. In other words, refactor as needed when you need to make a change. ...


1

Basically you want to create a unique key for every query that you can use to find corresponding result in cache. So, should be something like $key = md5(query); Then you test that key, in your example, if the file "/cache/$key.php" exists the you return the content otherwise run the query. Of course the cache will go stale, so you also want how old is ...


1

If I have stablished that I want my data sorted by criterium x, I expect that the n rows that I see in the windows are the first n items by using my sort over the whole data. What is more, if I scroll and get 10 new rows added to the table, I expect those new items to be at the bottom of the table, not mixed with the rows that were previously in the table. ...


1

The purpose of the repository is to provide an adapter around the database. It "knows about the database" so the rest of your code doesn't have to. So it seems quite reasonable to me that if you change your database schema, you'll have to change (or altogether replace) your repositories. The point is that you only have to replace the repositories, because ...


1

No, they are not the same bars, since you are calling new. Also I don't see $bars being used anywhere in wireFoosAndBars. Use the exact "associated" instances from $bars when constructing the new collection and they will be the same objects. You are correct in that clone is the only way to make a copy of an object. Modifying an object's properties, no ...


1

It sounds like the company is getting you to take the online tests administered by Fourth Valley Concierge (see here), specifically selecting PHP for the programming language component. You would need to speak to the company in question to see whether this is the only component you will be taking, or if they are requiring you to do the full UNITT test. As ...


1

You can't.... easily. Think about this from the user's point of view - why should their query be terminated because someone else is making another request? Fix your query to run faster so the system doesn't grind to a halt when somebody does something unexpected.


1

If you want typical request-response client-server communication use ajax. If you want bidireccional communication and for example sending updates from the server to the clients use web sockets. "It seems like I could use a simple node.js websocket server as an intermediary to between the client-side JS and PHP, passing commands from the client over ...



Only top voted, non community-wiki answers of a minimum length are eligible