I was challenged in my last post to deeper check performance of strings. I think it will be quite interesting to test out some cases and say which way of using strings is the best.
In this post, I will check several string usages in PHP 5.6 and PHP 7.
To simplify testing I created a simple function which gets 2 arguments: an array of callable functions to compare (as many as you want) with names to display in summary, and a number of loops to test the function…
As you may know, in PHP you can use single and double quotes for strings. These two lines are equal:
$str1 = "some string";
$str2 = 'some string';
// $str1 === $str2 returns true
The only difference here is handling variables placed inside quotes. Let’s look at this simple example:
$name = "John";
$str1 = "Hello there $name";
$str2 = 'Hello there $name';
echo $str1; // gives Hello there John
echo $str2; // gives Hello there $name
As you can see in double quotes variables are processed and in single quotes they aren’t.
But which one should I use?
I was working on a project in C# and ASP.NET MVC once. It was a long time ago. I can remember how happy I was. Earlier I was creating a project in PHP in the worst way: on an own framework. It was all old, shitty PHP. With big routing arrays, custom validation services, and ancient template engine, Smarty2.
When I started to create a project in ASP.NET I was astonished how many great features it has. One of them were annotations.
Time to speed the things up!
The series becomes a little too long, so its time to the drastic movement.
The application is working now. Here I’ll describe how to add a new note and set reminder as done. I think, that this will be a good foundation for extending the application.
Previously I’ve made a connection to Evernote and display list of all notes. Nice. But the project is about managing reminders, so let’s go to work!
First of all, I want to display only notes with reminders. It could be done using `NoteFilter`. It’s enough to add just one line:
`$nFilter->words = “reminderTime:* -reminderDoneTime:*”;`
It’s time to do some Evernote configuration.
To write an application that needs connection with Evernote I need a developer account. I have one, so in fact, you need it 😉
Go to https://dev.evernote.com/doc/ and click “Get an API key” button and fill the form with your data. You’ll get Consumer Key and Consumer Secret needed to connect with Evernote.
Now I suggest you create a test account in https://sandbox.evernote.com/. It allows you to test your application using test account so you won’t mess up your real notes.
Ok, we have installed environment, everything works fine so we can start creating our app!
As you may remember I want to write simple application extending Evernote by simplify displaying reminders and do some daily action on some specific notes.
I’ll start with displaying the notes. By now I don’t need connection with Evernote itself, so I’ll create some dummy notes in PHP.
Let’s start with the model for note. Model is the special type of PHP class which describes all data for the note. I need for sure: `id`, `title`, `description`, `remind at` date and maybe `created at` date. It is enough for now if the application will require some more information I’ll add it to the model. Continue reading
I hope, that setting up the environment goes ok 😉
In this post, I want to show you how to install Symfony on previously prepared docker container.
The simplest way to install Symfony is to use composer. Symfony has it’s own installation script, but I think that composer’s one is just fine.
If you have composer installed then it’s enough to call `composer create-project symfony/framework-standard-edition code` in your terminal (in the main directory of a docker, where `docker-composer.yml` file is placed, see PHPyths Buster: Project environment). All required packages will be downloaded and installed automatically.
Ok, time for some action!
I’ll start the project by setting up the environment. As mentioned in the previous post, I want to use Docker to simplify configuration for everyone who wanted to create this project with me 😉
I’m not a docker expert. In fact, a basic configuration for this project took me about 2 days! I could not find ready to use configuration so I had to create it myself using 2 or 3 different configurations.
But finally I made it, and I proudly present it to you! It is very simple and you might be surprised what took me so long 😉
As promised I’m starting with a real project to proof that PHP may be what you want to build a web application 😉
I want to show you complete way to build the functional application. I’ll go from setting up the environment, through installing the framework and required libraries, to deploying to the server.
I’ll use Docker with Nginx, MySQL, and PHP7 – I want you to make a minimal effort to start the project. In addition, you won’t need to install something on your computer (well, except Docker itself) and your computer will be clean as always. You could also do the examples yourself and easy experiment with the code in the same environment. If something will break you could always let me know and we’ll fix it together 🙂