Tag Info

Hot answers tagged

5

There is no hard and fast rule which methods an object must have. Something is an object if you can talk about it as an entity with a name that is familiar to domain experts in either your problem domain or the solution domain. In essence, if you have a related set of properties and behaviors that you can refer to by a single name, then that set of ...


4

I am no fan at all of embedding PHP inside HTML (like your first example). That just makes a huge mess of things and makes it difficult to separate the code from display. Some systems are set up to use PHP as a template engine so there's no avoiding it inside of views. But in systems I build from scratch, I never do the former, and don't do a lot of the ...


4

The best way to secure your PHP code is through a contract with your clients. Sure, you could probably buy or write your own obfuscator, but that would hinder you during support of your own product. Consider that most clients will not have an idea that they could even look at the source let alone read and modify it.


4

Levenshtein, SoundeX and Metaphone functions could be helpful. You might need to break the original answers to words, in order to make a better comparison. Also taking out and, [space]n[space], & from both correct answers and the user input could lead you to a much better results.


3

The general practice is to put HTML in a template. A template contains minimum programming code: it's mostly HTML, with calls to variables and basic loops and conditional statements. The reason for that is that putting too much programming code in templates would: Make testing difficult, Make the reading and changing of the template difficult: the ...


3

The rule is not to depend on infrastructure, but instead you can create an interface in terms of the business to communicate with that infrastructure. These are your services. Sending mail is a business requirement, or service, but how you send mail is up to you. You may want to create your own business-specific mail interface, and one of the ...


3

You could send the entire contents of a stored procedure to be executed by the database and return the exact same dataset(s) or do the same code execution without losing any performance, but my guess is that's not your problem since you're still maintaining the code in the MySQL language. There are probably a lot of calculations in your stored procedure and ...


3

I could be waaaaaay off, but... It seems that a model is necessary to use the library, you just don't care which one, right? Further, the library doesn't care how the model gets its data, or where the data comes from, it just wants an object that meets the criteria of the interface. If the library doesn't need the connection object, then make that the ...


3

I'll leave whats 'bad practice' to the bloggers to fight over. I personally keep queries within the business-logic objects. So yes, User, Order, Sale, etc. I'd find it very inconvenient if they they were all in a separate file. That would be unnecessary added complexity and frankly kind of annoying to have to keep referring back to the file. If for ...


3

The syntax has to cover three things: Some way to specify the placeholder type Some way to specify the placeholder source Some way to handle arrays You already have the type-specification covered with the ?type syntax - I'd keep this as is and combine it with elements to handle the other two. The array handling using [...] (with ... being another ...


2

I suggest making all parameters start with ?. The advantages of this are: It extends an existing familiar paradigm. There won't be any syntax clashes or ambiguities. There is a clear visual indicator of what things are placeholders. So name identifiers would look like: SELECT * FROM ?ident:table WHERE id IN (?int:id) If you want to implement more ...


2

You should test sufficiently to provide adequate code coverage. Sufficiently (and adequate) vary on the risk associated with an undetected problem in your code. The cost to fix a problem after development (assuming a classic SDLC) is significantly higher then the cost to fix during development, but the risk may be minimal. So, really that is another way of ...


2

The reason you see a lot of html templating is probably because of an "appearence driven" workflow. I.E. You start by coding up an HTML page that "looks right" then add in the dynamic php elements later. This works well if you also follow a classic Model View Controller pattern -- essentially you do all your business logic in php before invoking the ...


2

There are several aproaches, the one hand, using templates from the server side like Smarty, Twig, etc. I don't recommend this approach because you're coupling your presentation code to the technology used in the server (like php, python, ruby, java, ...). The other approach is to use client side templates/frameworks for the view (like ember, angularjs, ...


2

Multiple inheritance is only supported in few languages, notably C++. It can lead to some very strange effects if the same methods are defined in two different classes that are both extended by a subclass. Instead, you should use interfaces (http://www.php.net/manual/en/language.oop5.interfaces.php). You will have to define (implement) the methods in those ...


2

An extended class is always dependent on a single base class, that is, multiple inheritance is not supported. Also, in the UML example you posted there is nothing that has 2 parent classes, just some classes that all extend one class and implement an interface. Furthermore, most UML tools are not bound to one specific language's syntax and quirks, so not ...


2

You're well on your way to a successful implementation of a user registration process. However, there are still some unknowns that you haven't addressed, that can impact your desired outcome. How are you tracking that the user's account has been activated? It seems that once the user clicks the link to activate, there's no record that it's been activated ...


1

I would go with what you have listed in the Example 2. Reason to do so is simple - It keeps things simple. Rather than naming the files really long and using a class name really long does not help in anyway. To bring in the effect of link i.e. between the abstract and derived classes, please use namespaces or folder structure. IMHO, class names need not be ...


1

In PHP you cannot have a class that extends two base classes - see the diamond problem. Your UML diagram shows a base class and an interface. In PHP you could implement one of the subclasses in your UML like so: class Customer extends p-info implements i-control { // Concrete implementation... }


1

The first thing I can suggest you is to take out the Logic from Mark-up or basically avoid to write in-line logic in your mark-up. So you can re-write your first example like this: if ( in_array('name', $error) ) { $class = 'form-error'; } else { $class = null; } // or ... $class = in_array( 'name', $error ) ? 'form-error' : null; if ( isset($name) ...


1

Yes, PHP arrays are dynamic, in the sense that one can create an array, insert new elements, delete elements, etc. without ever worrying about its size. The array grows or shrinks as needed, automatically. You didn't quite fully "do your homework" though, since most PHP programming books would have told you the above :) By the way, if you need a ...


1

"Sign a legal contract" This is a typical response to this typical question. It's neither right or wrong. It's an opinion that doesn't answer the question. It's like saying "keep a copy of the receipt" when someone asks how to keep their jewelry safe from thieves. The correct answer is buy a big iron safe. The real problem is the question is often a waste ...


1

As asked in the title, you are probably looking for the Data Access Object pattern, that is also discussed in this StackOverflow question. The point is using software layers to separate the program logic from database structure, because this way you could change your database schema, the names of the tables, and modify a small and isolated part of your ...


1

It comes down to an if statement finally somewhere in your code. Personally I've something more similar to this: if ( true === (bool) $_SESSION['user']['login'] && 0 < (int) $_SESSION['user']['id'] && time() <= ((int) $_SESSION['user']['last-activity'] + 20 * 60) && $_SERVER['REMOTE_ADDR'] === (string) ...


1

As @Songo's comment points out: "Frameworks won't write ur business logic". Once you get beyond simply processing a form and saving the information to a database right away, you'll most likely need some of the OOD knowledge to help you implement features in a maintainable, well structured way that future developers won't want to burn you at the sake for. ...


1

In many applications, the 'web app' is one part of the project alongside many other apps with many other non-website purposes. A trivial app could, for example, obtain input from a user, save it to a database, and redirect to a new page. A more complex app might access several other internal applications, and perform additional business logic and ...


1

Using a framework while not understanding the basic concept of OO will eventually give you a hard time. Knowing about OO will give you insight into when to use which design pattern, how to properly differentiate functionality and assign them to different classes etc. So in fact by learning how a framework is set up will provide you with a benefit for the ...


1

Based on the information provided: The database will be used to drive a custom CMS system which is intended to store a interconnected system of data. 'Interconnected' implies relational, which is why you should use a traditional relational database design. It will involve customer data, location data and job data. Already there's three tables ...


1

what could be the User object Behavior ? I cannt find any ! login, its an auth lib. thing so i should not include it in user. posting articles is a Post object thing; again user conduct it; but its more of a post object concern to create a post right ? User may be the main Aggregate object in a blog; yet the user is more like the Creator of ...


1

Bandwidth limiting is supported by PHP Ext cURL. The settings you are looking for is: curl_setopt($ch, CURLOPT_MAX_RECV_SPEED_LARGE, 10240); aria2c is faster than cURL on mirrored downloads, because it allows fetching parts from multiple sources in parallel and combines them. this is not supported by cURL, afaik. rebuilding this feature on PHP side is ...



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