New answers tagged

0

The real question here is "what is the consequence of failure?" If you delete something and it's not there, who cares? You wanted it gone anyway. If you want to insert data and it fails, what can you possibly do? Nothing, really. How, or even if you communicate errors largely depends on the fault tolerance of that transaction. Deleting something that ...


1

What you have here is using the Singleton Pattern to ensure that all callers receive the same instance of the connection object. Sounds efficient to being with and, so long as your application is purely single-threaded and never tries to do more than one [database-related] thing at a time, it will probably work quite well. If this is a particularly long-...


4

No. Unless you are on a really crappy O/S (or, to be precise, your ODBC library and/or database access drivers/library, which may or may not be part of the O/S proper), your code is not actually creating/using/closing database connections. It is creating/using/closing database connection objects, which are a wrapper for the underlying connections. The ...


0

Is instantiating a single database connection like this and returning that instance to all callers a good software engineering practice? That depends. The code as it stands doesn't check if the connection is still alive, and reconnect if it isn't. Assuming this is a simplified version and that the real code performs such a check, then: As long as the ...


0

pecl apd was last updated in Sep 2004, and is not currently maintained. I don't think it's a great idea to use it. That said, you could try renaming scandir to something else first, with rename_function: rename_function('scandir', 'scandir_old'); override_function('scandir', '$path', 'return scandir_new($path);'); function scandir_new($path) { $...


0

I'd take a look at what would be useful to whatever calls your delete method. At the moment, client code calling this method will see a false condition when the item isn't there to delete, or is not able to delete... How should the client code react? Is it important that your client code does something in either case? Without knowing what the application ...


0

The answer to your question is: it depends. What you are currently doing is called exception suppression, that is calling a method which may throw and returning false when it indeed happens. Is it a good practice? That is difficult to answer without knowing exactly what you want from the method where you are suppressing the exception. I personally have ...


-1

One of the benefits of using Visual Studio for Asp.NET MVC is the seperation. When I develop something using CakePHP, it feels like everything gets jumbled into a few single files and the code will get clunky. If you are still going down the road of MVC (which I highly recommend), you might want to check out DJango or even Asp.NET MVC with the community ...


3

Both solution are viable, they simply don't apply to the same use-cases. a) manipulate the DOM via JavaScript : This result in a more heavy first page, but after that you will use less bandwidth, because you will only fetch what you need, and not rebuild and send everything. And in the cases where you don't need to fetch anything, it will be really quick (...


1

With a little guidance from @RobertHarvey I found a StackOverflow answer about Presentation Models. A presentation model is a utility class that is used to render data on a screen or report. Presentation models are typically used to model complex data structures that are composed from data from multiple DTO’s. Presentation models often represent a ...


2

Your understanding is correct. Keep in mind that different frameworks use different approaches, so something which would for instance apply to Laravel won't necessarily apply to, say, Symfony. This is especially true when it comes to deciding where the logic goes: some frameworks use models as basic objects containing data, but practically no logic by ...


2

Preface For any given project, the answer to this question will likely differ. This is simply a result of structure and overall philosophy. It may be easy and straightforward in some instances, but extremely difficult and complicated in others. However, if this is a difficult problem, that is a very strong code smell: something is likely quite wrong with ...


2

If you have a small, fixed number of different part types which will be seldom extended, you can keep this pragmatic and give your PersisterFactory a handful of different methods like CreateDesignPersister, CreatePlotPersister or CreateSelectionPersister. If each of those classes contains only a single persisting method, even that maybe overengineering, a ...


1

What you are decribing is a common design pattern, and, as @Robert commented, its name is abstract factory remember SRP means, that a entity must have only one reason to change not that it must only do one thing at all, or return only one type of result. So no, you are not breaking SRP.


0

My question has been answered in this article: http://php-and-symfony.matthiasnoback.nl/2015/01/some-questions-about-the-command-bus/ The command bus has no return value. So instead of waiting for the ID to come back from the database, the ID should be one of the values of the command object. If you then hand it over to the command bus, and nothing fails,...


1

PHP is an object-oriented language, or at least it somewhat reasonably supports object-oriented programming. The main idea of OOP is that objects send messages to other objects and those objects then respond to those messages. The metaphor of "messaging" is apt: when you send someone a message, all you can see is their response. You cannot see what they do ...


0

Are there any more options I should consider? have a look at php constants instead of global variables consider using bit fields instead of a SYSTEM variable or constant


0

why not iterate through the tiers? that should solve your problem without any overhead: protected function getPath() { $classname = get_class($this); do { $path = BASEPATH. '/'. $classname .'/'; if (file_exists($path)) { return $path; } $classname = get_parent_class($classname); } while ($classname); return NULL; } or, in your code, ...


1

I see all websites (THE big ones) make both PHP and HTML in same page .. Do I need to make all my website pages as PHP and embedded HTML inside it ? The fundamental problem here is that you're seeing a thing that websites you perceive as being big ones and then you're assuming that's a good thing to do. It's not. PHP is terrible enough on its own; ...


0

Yesm all of these things are correct but in the end when every page is loaded they are all converted to an HTML formatting so basically PHP, Bootstrap, CSS, JS are just basically all additions with makes data entry or forums all possible but the real question is what will this be used for and how can we , you implement an infrastructure for storing all data ...


0

Yes you can avoid PHP inside HTML. Use PHP as an API. Load up the page with embedded JSON, and render out the page client side with JavaScript. Then, instead of requesting HTML/PHP via AJAX, request more info formatted as JSON.


2

Ahmed, Web pages can be built in just html. In fact, that's how the web started out: with just simple html pages, things we would call today "brochure-ware". The user requests a page and the server delivers a mixture of text and pictures, and then it's done. There is no interactivity, like individual preferences or searching a database. PHP came later ...


1

You're confusing whereHas and with. The with method will let you load the relationship only if the query returns true. The whereHas method will let you get only the models which have the relationship which returns true to the query. So here : (new App\User)->with(['address' => function($query){// filter code}])->get(); will return all the ...


5

Short answer, no. But mysql_real_escape_string isn't the only thing that protects you here. See : $text = mysql_real_escape_string($_POST['text']); // $_POST['text'] == "1 OR 1=1" $result = mysql_query("SELECT * FROM login WHERE id = $text"); You're not protected here, and an injection was made. So your quotes are protecting you against this here. You ...


0

You are basically inventing a database on top of a database. A relational database already have a system to represent properties for entities - it is called tables and columns. By creating your own system on top of this, you are introduction a layer of complexity and at the same time loosing many of the benefits of a relational database. For example this ...


1

In this example of the command pattern, returning a value is handled with a callback. I would imagine that a future or promise would work just as well. Decoupling of the return type is not mentioned in the example; in systems I've seen that are similar to this where you subscribe to an Event (the moral equivalent of a "generic" callback), one would return ...


0

<?php $t = Lang::get('myLangFile') ?> <div><?= $t->helloWorld ?></div> This works and guarantees me my views will work regardless of who's calling them and basically costs nearly nothing in terms of performance because instantiating a Translations will not copy the array containing the information unless a change is ...


1

Usually you have to query DB every time you render a page. Q1 - Yes, you just have to select all items ordered by created date (well, you don't want to select ALL, but only how much you need for current page - see 'Pagination') Q2 - Yes. Same as above. This might not work exactly as you want, because SQL databases are not search engines. In SQL DB you can ...


2

Yes, this wastes memory. However, consider this: typical virtual server for a small web site has a few hundred megabytes of RAM allocated to it; for a larger site that might be upgraded to a handful of gigabytes. A typical model object might use up a few kilobytes and have a lifespan of less than a tenth of a second. Now work out how many requests per.second ...


-5

1.When I only need a few variables set, isn't it memory consuming to create an entire object? E.g. an entire site_object just to pass on site_id's and site_names? Yes, because for every object you create from the model, that consumes memory, and is not garbage collected into the CLR(C#/.NET) does so. Though if you are reusing that model within the ...


0

I haven't done a lot of coding with PHP, but generally There are few steps you can start with, Create interfaces for each responsibility of the God Object and alter it to implement these interfaces. This is a minimal risk as there are no actual changes done in logic, just adding interfaces. When you want to modify a section where God Object is used, you ...


5

You're responsible for enhancing and maintaining the codebase. Is that the only responsibility that you have ? If it is, then the game is pretty simple. Start small. DO NOT TOUCH THIS GOD. It's a God for a reason. It is used everywhere, it is too massive and too powerful, you won't be able to test it anyway and any change could break ANY part of your ...


3

The first question that comes to my mind when reading your question is not how one could refactor such a beast (»1,100 files and 120,000 lines of code.«), it is more »why on earth would anybody do that?« I know the strive for the perfect design and I too love clean code. But ont the other hand, I have only 8h a working day and there are funnier things to do ...


1

Php is fine for your project, even though there are better alternatives (hello NodeJS). Ajax won't be real time. You'll have to manually make requests (even if they're made every X seconds) to fetch new datas. There won't be any conflict but there might be performance issue for you and your user. Sockets are more interesting for your project because they'...


1

Ajax has better compatibility, but web sockets are more efficient and simpler (as you won't have to deal with issues about long polling, which can be a hassle to get right sometimes). These days, relatively few browsers support ajax but not web sockets, so my suggestion would be to do it that way, simply for the sake of simplicity. Note that efficiency isn'...


0

I would make a dynamic scope in the model (https://laravel.com/docs/5.1/eloquent#query-scopes) which gets as input the permission and modifies the query select to return only the allowed fields for specific permission.


0

Maybe in your case - having centers and radius would be easier, instead of combining the circles, just to check if the distance of the user to the centers of the drivers is less that the given radius. Something like: SELECT * from drivers where ST_DISTANCE(drivers.center, POINT([user.lon],[user.lat])) < drivers.radius; /* assuming drivers.center is of ...


1

It's quite unclear what exactly you are asking. We can't write an Elasticsearch tutorial here. As a rough overview: You should have an ES index that contains all the information you possibly want to search/aggregate/facet and also all or most information you want to display. Your search has two basic parts: The search itself that returns the products. ...


0

It turns out that this feature is called time travelling and it comes from flux or redux. I use redux, go check it out: http://redux.js.org


3

Only scalar data (boolean, integer, float and string) can be contained in constants prior to PHP 5.6. From PHP 5.6 onwards, it is possible to define a constant as a scalar expression, and it is also possible to define an array constant. It is possible to define constants as a resource, but it should be avoided, as it can cause unexpected results. Source: ...


-3

First - MainMa have propably right in comment (about violating terms of use - there is a reason why there is captcha ;d ) Anyway - to do that in PHP - you must use HTTP Client solution. The best (in my opinion) and well documented lib for this is Guzzle http://docs.guzzlephp.org/en/latest/


1

Adobe Acrobat (and other PDF software, as well) has many annotation features. The one that I would recommend is the "rubber stamp". You could have a red X and a green check mark defined as stamps, as an example. You can then plop them down on the PDF image where you want and then re-save the PDF.


1

Well, see it this way: your input scan is already a raster image (the fact those raster grafics are in embedded in PDF is mostly irrelevant), so a raster image based process is all you can expect. Utilizing OCR might be an option, but it would probably only complicate the process with no real benefit and an additional source of potential errors. If you want ...


1

Although for most cases the second approach is probably better, cases when you want to hide implementation details by retrieving a generic interface from a method by passing a flag (used to choose the correct implementation) and data to a factory, this seems more like a business rule and as such the first approach would be the go-to solution here. The key ...



Top 50 recent answers are included