Tag Info

Hot answers tagged

8

The problem is that a password should appear in plain text as rarely as possible. In your case, the password appears in plain text in an e-mail. This has several drawbacks: If the account of the person is compromised, the hacker gets access to your website as well. If there is a malicious man in the middle, he can access the password with ease. ...


8

Why cant be a global Standard to do all Simple and Common things? We tried that. The concept was called UNCOL, and the idea was that it would be ported to every architecture in the world, everyone would use it for everything. As you can tell, things didn't work out that way. Why not? Because programming is a complex activity, and there is no single ...


8

I'm going to build some public public PHP packages. Public as in "Open Source", "public to the whole world"? Then do yourself a favor and do as much validation as you can as long as you do not suffer serious performance problems. Even when you provide some documentation saying "this function does not handle left out parameters", expect a lot of people ...


7

One possible reason is that you might need to edit PHP files from remote and it is much faster to access the server via SSH than remote desktop. However, protocols such as SSH only give you access to the command (textual) interface of the server, i.e. the Terminal/Command prompt. Editors such as Netbeans require a graphical interface, yes you can access ...


7

They replaced TranslatorX64’s tracelets with the new HipHop Intermediate Representation (hhir), and a new indirection layer in which resides the logic to generate hhir, which is actually referred to by the same name, hhir. From a high level, it is using 6 instructions to do the what required 9 instructions before, as noted here: "It begins with the same ...


6

Don't do it. There is no proper way of doing it. Documenting which places a function gets called from is a remnant of the structured programming paradigm of the seventies and the eighties. I actually do remember back in 1989 a professor asking us to document functions this way; I never heard of anyone doing such a thing ever since. This paradigm has been ...


5

All three are wrong, because you are storing connection strings in source code. Source code is not the right place for configuration, because you are not expected to have to change your code (and so, do all the regression testing) every time your database moves or every time you move from development database to staging and to production database. Instead: ...


5

Let's immediately get the Turing-completeness disclaimer out of the way and say any language can probably approximate any runtime feature of any other language. Good? Good. The main difference between the Node.js approach and a Python threaded-server (or a typical Java HTTP server implementation) is that Node.js is single threaded while the latter two are ...


4

Simple answer: Because you will need it. On productive unix/linux environments you will likely only find vi/vim as editor. Also you will not be allowed to install additional software on the productive server (like your favourite IDE). Additionally most server environments will have no GUI (when speaking of unix/linux) Therefore remote desktop is no ...


4

What matters about programming languages are the semantics, not the syntax. However, syntax is a vehicle for semantics. It is easy to show that two languages can have incompatible semantics (e.g. unrestricted pointers vs. memory safety, or differences in type systems). Let's focus on the syntax and semantics of variable declarations. When we declare a ...


4

You are over-using SRP. Let's take a look at mappingConcern's creation-and-initialization version: public function mappingConcern($data) { $parameters = $data; $product = new Product($parameters); return $product; } $parameters is the same as $data, and $product is returned immediately, so it can be translated to: public function ...


3

Why create a whole other classes to handle those responsibilities? Because when you're doing Object Oriented Programming, your focus should be on the objects. They are your unit of work for making the design and providing abstraction. And most importantly, they are your unit of reuse. By letting them change for different reasons, you're forcing people ...


3

Honestly, there is not much value to it. 1) Most people use their own password that they remember. If they do, then making them change their password will take longer than filling up an extra field during registration. The benefit of your system may be that by then the user is registered so you'll not lose it. 2) If they use a password manager it is ...


3

The usual practice is to distinguish between the login name, (often the users email address), and a display, or nickname/moniker/handle, which you can allow/force the user to input themselves. The session management then uses the login name for all transactions, (usually via a per session hash to avoid people being able to recover the actual login name), ...


3

I've never seen the point of a class that only queries the database and returns an array (or DataSet or DataTable for those in .NET). The mapping of columns in a database to properties or fields on an object belongs in its own class, not in the constructor. The whole point of a data mapper is to decouple the database schema from the object model. By passing ...


2

Most likely, your MVC already includes a variable accessible within the controller for accessing the user's information. If you store user roles in the database, you can restrict access to certain areas of the site in the router based on role, or on a page-by-page/controller class-by-controller class basis. Whitelisting should probably happen in the front ...


2

As of PHP5, type hinting is a thing. The most important distinctions are the following: You cannot type hint scalar/numerical, string, Resource, or Trait data. You can force parameters that are objects, arrays, or anonymous functions. You can type hint using interface names, class names, object keyword, array keyword, or callable keyword (for anonymous ...


2

You're in the right neighborhood. Most PHP applications will have active sessions for all page views, regardless of whether a user is logged in. It would essentially do a session start() at the beginning of the script, and a save() at the end. That session would exist for the entire visit to the site, or longer, depending on how you have PHP set to expire ...


2

That is relatively safe, providing that you use SSL (HTTPS, use ssllabs to check the security of your site), and you configure your cookie to be domain-specific, have an expiry date not too far in future and be "HTTP-only". Use mcrypt for encryption (there's support for that in PHP) and the salt key should be reasonably long, and kept SECRET, or change for ...


2

Sounds like you are not very good just yet with the responsibility assignment in programming. Have a look at General Responsibility Assignment Software Patterns. They will tell you exactly where to place each method and property. You want to have a class that defines an object with it's own properties and methods to act upon it. You don't want to just ...


2

The code sample #2 you provided is preferable in my opinion. What if tomorrow you want to have CachedProductData, you would only update product data class, or rather introduce another layer. If you have both classes merged like in example 1, you would be updating both responsibilities. So, Single Responsibility Principal would be broken if you choose ...


2

You shouldn't catch the PDOException at all. Now, you should have some sort of last resort exception handler that catches all exceptions and logs them. PDOExceptions should be caught there. But you shouldn't catch them anywhere else. In my understanding, PDOException indicates either that something has gone very wrong with the connection to the database, ...


1

Since a data mapper should have a single responsibility, it should only map the results of the query to an object or object(s) and return that back to the caller. In your case we have: Product Motor So, I think one would definately have mappers for those objects defined. I beleive your choices for mapping product and motors are: Composition. ...


1

I would argue its impossible to handle all exceptions the same way. I think you should let it propagate back to the calling code as it ultimately knows how it should handle the exceptional situation. Just to think of a (maybe weird) example. Imagine you have an blog. An each hour you query the database for new articles. But luck isn't with you and your ...


1

I would be worried about doing this unless you clearly state to the users that they can login with Google account to your website. What you are talking about seems like you want people to use their Google accounts to login to your system. For that, I would look at this library or something similar: PHP Library for Google Authenticator


1

Migrations should change the data when needed - otherwise they don't fulfill their purpose of taking a database that works for an old version of the application and making it work for newer versions. Migrations are also the best place to do this, because you can make assumptions on the database's structure before and after the migration is run. One thing to ...


1

To start off with your login, I'd like to say that the password should be stored safely as well(This is probably not your main concern). Whenever you use sessions or cookies, you're vulnerable to session hijacking. Now on that link, there are ways to prevent session hijacking as well. Like: Encryption of the data traffic passed between the parties by ...


1

In the words of Nike and (recently) Shia LaBeouf, just do it. There are plenty of free resources online, though I utilized portions of this book to get me started. Just start messing around with the class-related syntax at first to get a feel for it and build some simple classes (I started with a class or two that did fantasy football point calculations). ...


1

There's no standard, this is entirely up to you. If you are going to implement type checks, keep in mind that you'll only need them for scalar values. PHP supports type hinting for arrays and objects. Also, there probably isn't a reason to throw an exception on every type mismatch. Consider this function: function getById($id) { // Get item from db ...


1

IMHO "because you may need to edit files on the production server and there is no IDE/GUI on production servers" can't be the answer. In any professional shop an ordinary developer has no access to the production server. If the shop has a a size of > 10 employees they will have a system administrator/devops team for that. Even if we assume the team is so ...



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