Tag Info

Hot answers tagged

13

Note: This is written from a highly opinionated stance. Long ago, when the web was young, you wrote a web app in perl. That was really it. That was your only choice (unless you really liked working with strings in C). (And yes, I'm glossing over great swaths of ASP and the like... I'd rather forget those days.) There were great and large applications of ...


3

I use MVC in both. Yes the views server-side are very simple, but that's ok. Still nice to have separation of concerns for all the usual reasons.


3

There is nothing like that in PHP, however you can go for something like this -- even tho I'm not really recommending it: if ( in_array(foo(), array(1, 2), true) ) ... Please note that it's not gonna work on && conditions and you're limited only to == and ===.


3

Here are some points you should take in consideration: Readability: long regular expressions are difficult to understand. Use comments (and eventually break one long expression into several small ones, if possible) to make it easier to read. At the same time, the piece of PHP code in your question can (and should) be refactored to make it more readable. ...


2

The issue you are facing IMHO is a growing amount of technical debt. While usually attributed to poor design, I attribute to overall poor software engineering practices. The problem is, once you've accumulated some, you'll have to pour a bunch of resources in to get out of it before you start seeing major improvements. But in the end, I promise the work will ...


2

Create a table which will store information about notifications: TABLE notifications event_id user_id datetime // date and time when notification must be sent Every time someone joins some event, you should insert a new row in the notifications table. To notify users, you need script which will perform a mysql query like: SELECT * FROM ...


2

I still think it makes sense to stick to phpDoc to document PHP code. It is the standard recommended by the php PSR project. It is also generalized into the annotations concept, as it is used for instance in Doctrine. Another argument for phpDoc is that Javascript and many other languages have it's analoguos commenting system. After much time spent to try ...


2

I'll attempt if not answer your question, at least give some hints. As a side note, I've contributed to refactoring of several medium-sized projects (although not as big as yours), especially the ones which had data access directly mixed with business code, so the answer is partially based on my personal experience. Identify the problem The first thing I ...


2

The abstract Controller class can't create the right <concrete class>Domain classes, because it doesn't know which concrete class it belongs to and which Domain and View classes it should be associated with. What you can do is pass in the Domain and View classes from the derived class's constructor. abstract class Controller { private $domain; ...


2

Generally, you use Web frameworks (or languages, in PHP's case) to serve and store persistent data. What do I mean by that? Well, Twitter is the go-to example. When you make a Tweet, that gets stored in a database somewhere. Then, when you look at the tweet again, it's loaded from the Database and sent to you. In your case, there is no need for persistent ...


2

What are the downsides of structuring a website this way? The main problem is dealing with pages that change per user. For example, your website has an user system, so for each user that logs in, would you then generate a new page and cache it? Is this flat out a bad idea? No, it's an excellent idea. As a matter of fact, static content is often ...


2

If you have a ColorModel that can represent all possible colors and that you can convert to without loss of information, then you can designate that ColorModel as the 'canonical' model. The conversion between arbitrary ColorModels then becomes a two-step process: First you convert from the source model to the canonical model and after that you convert from ...


2

Let me ask a question : what you happen if in your PHP version I would write: // PHP class Sample { public function __construct() { $dispatcher = new EventDispatcher(); $dispatcher->addListener("sample.event", array($this, "onEvent")); $dispatcher->dispatch ("sample.event", new WarnEvent()); // oops? } ...


2

I think this comes down to encapsulation. If you have to offer public methods to check Coupons, then you can't guarantee that the user of your API will call isCouponValid before calling isCouponUsed, so you have to add the extra check. But these situations are always questionable, and usually suggests that your design does not follow principles such as ...


1

Most CI servers are somewhat language agnostic -- at the end of the day you are really just executing shell scripts with some fancy reporting -- so your general premise is correct. The physical deployment of PHP apps is typically pretty simple -- they are just files on disk so rsync is your friend here. The difficult parts come in with things like user data ...


1

One of the most important things when using a programming language is understanding what it's weaknesses are. As many languages have substantially different weaknesses, it is often a very bad idea to directly port code from one to another. In both examples you have provided, you are presented with a fairly severe typing issue. Even the dictionary has a ...


1

Even though this could work, this might be a little overkill. Will issues in scalability still arise in modern Prolog implementations? Beware of strings. In some implementations, the generated code for querying in_group/2 will result in a lot of branching, as in if "Alice" then ... else if "Bob" .... Replace double-quotes with single-quotes, ...


1

Basically I have these checks integrated into the class right now - isCouponUsed() calls isCouponValid() in order to check that it's valid first. Is this a good idea, or is it better for me to use isCouponValid() outside of the class and then pass that value to isCouponUsed(), such that isCouponUsed() should just be concerned with validating a ...


1

You should be concerned about classes driving the behaviour of other classes. This means to be wary(not necessarily always avoiding) the dot operator. Suppose you are a pizza delivery guy, and you come to my house looking to deliver me a pizza, are you going to reach into my wallet and take my money? What if my money is on the fridge? This is called high ...


1

Everyone has their own wishlist for routing. Which is why so many people have looked over the landscape, decided that everyone else's routing is bad, and written a new one. That said, the top of my wishlist includes hierarchical routing. That is, based on the start of the URL you should be able to route to a component that takes the next component and ...


1

What are the downsides of structuring a website this way? Obviously, the downside is inability to do typical "dynamic" stuff like CRUD with forms. Of course, you can still use some 3rd party API for contact forms and comments, like Disqus or Muut. Is this flat out a bad idea? No, it is an excellent solution for static sites. It is indeed very ...


1

In principle each arithmetic pseudo-random number generator (such as PHP's) has a finite period after which the same sequence of numbers will repeat. And most generators will generate a fixed minimum number of bits (often 32) for you internally at each step, no matter how small the range of results you asked for. So generating each digit separately will eat ...


1

There are a couple of ways to approach this, depending on your requirements and scale. First of all though, I don't believe a CDN is appropriate in this case. A CDN is used for caching of static documents to provide faster delivery of those assets to end users. It's not relevant for centralised storage or management of files. At the larger end of solutions ...


1

I tweeted to http://whatsmybrowser.org and then opened it up using the latest Twitter app on iOS as of 12/1/14. Here is my user agent: http://www.whatsmybrowser.org/b/IQBX258 Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12B435



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