An introduction to new php 7 book

php 7

php 7


I had started writing a well documented book on PHP 7 in the month of March but I’d to leave the project unfinished as situation demanded.
I’m eager to go back to my unfinished job. Before that I thought it would be good for my readers to give them a glimpse of how I had started it.

Note from Author

I always love to write for the beginners. I love the innocent moments of bringing few new things to my dearest readers. And this time I’ve done it by taking a completely different approach. You build web applications and learn php 7 simultaneously.
Continue reading “An introduction to new php 7 book”

how to become a good wordpress developer

It’s not at all difficult to become a good wordpress developer.

Wordpress developer

WordPress developer


People often make a bad mistake. They think WordPress is only a simple, user friendly blog-engine. They use WordPress as a blogger not as a web programmer. There must be some misunderstanding or a set of thinking-patterns that is actually a wrong action attributable to bad judgment. If you want to become a good wordpress developer, you mustn’t make this mistake.
Continue reading “how to become a good wordpress developer”

How to become a good PHP developer

I want to answer this question from a beginner’s perspective. You’re reading this article because you’re a PHP developer with little knowledge and you want to make ‘coding as your forte’.

php developer

php developer

Closed or Open?

I’ve seen two sides of server side scripting. I had started learning PHP and MySQL much before I tried coding in C# and ASP.NET. I had not been developing with ASP.NET for long because I’d to leave it. Was it destiny? Actually I didn’t like the closed source. That was the real reason. Besides it was not my profession. I was not a professional PHP developer at the beginning. I was a data-journalist who wanted to be an Author and Ethical Hacker.
Continue reading “How to become a good PHP developer”

How I joined multiple Bootstrap themes with my official WordPress site

I thought I should write down this without delay and share with my readers. These are bits and pieces of my experiences of writing my official website sanjibsinha.com. It was a kind of trial and error method that I had always expected that, well – touch wood, it’d survive somehow.
And it survived the experiments. Google started indexing it and I think the time has also come to play with Google analytic.
Let me finish it very fast and start from the very beginning.
I decided to inject multiple bootstrap CSS styling in my website. It’s a kind of bootstrapping wordpress.
As you know, when you start building a wordpress site from scratch you need few files at the very beginning. They are – style.css and few more PHP files like index, page, home, header, footer, sidebar etc.
I decided to make the front page a static page so I injected a ‘front-page.php’ file in that beginning procedure.
As of now I am keeping three styles – two of them are open source bootstrap theme and the other one is the mystery (please download it from my github repository).
The first step is – make your default style intact so that it does not break.
My ‘style.css’ code:
@import url('css/font-awesome.min.css');
@import url('css/bootstrap.min.css');
@import url('css/animate.css');
@import url('css/style.css');

body {

}

Next get the link in the ‘header.php’ file:

bloginfo('stylesheet_url');

I don’t want the ‘Home’ navigation in my first page menu bar so just excluded it with a simple code:
wp_list_pages(array('title_li' => '', 'exclude' => 4));
Remember wordpress keeps everything as ‘post’ inside database. My home page post id is 4 and I’m excluding it from the first page navigation.
You know the other wordpress pages more or less follow this same logic:

if ( have_posts() ) : while ( have_posts() ) : the_post();
I decide to get the permalink, time, title, and content after that so the functions are easy:
the_permalink();
the_title();
the_time('l, F jS, Y'); //you can change the format, please search in the codex
the_content()

You should also keep an error message if something goes wrong with your code.
_e('Sorry, there are no posts.');
As I said before: there are three themes as of now. So I need two more template files. One is for Blog and the other, the custom one is for any other purposes.
You need ‘header-blog’, ‘footer-blog’, ‘header-custom’, and ‘footer-custom’. And in the related template file don’t forget to write like this:
get_header('blog')
get_header('custom')

Besides these simple routine I decided to show one category in my custom styling. I’ll write this part in detail.
Finally my website looks like this:

The Home page:

The blog Page:

The Contact page:

The archive page:

And finally I decided to show my ‘PHP’ category posts in the custom styling:

So this is it. For full code please visit my Github repository:

GITHUB

Null coalescing operator in PHP 7

Let us consider a code of checking the age first. It checks whether the ‘age’ is given in the form or not. If it’s not given, then it says ‘not mentioned’. When it’s given it just spits out the age. Very basic thing we normally did when php 7 had not come.

$age = isset($_GET['age']) ? $_GET['age'] : 'not mentioned';

var_dump($age);

As usual it’ll give an output of – ‘not mentioned.’ Now we write this code with the age given.

Continue reading “Null coalescing operator in PHP 7”

Adapter Pattern in PHP

Can we Adapt SMS into MAIL?
Now we’re going to do an impossible task.
Are you prepared?
Can we start?
This chapter is about the adapter pattern. It’s one of the design patterns that you’re currently on. Let us start with a real world example.
You know that internet connection is absolutely necessary for sending emails. Is it true in the real world? You’d say, well, I know that. An internet networking is a must.

Continue reading “Adapter Pattern in PHP”

Chain of responsibility in php

Let us see how Responsibility can be Unchained!
In object-oriented design, the chain-of-responsibility pattern belongs to behavioral design patterns segment. The simplest example contains a person using ATM. He’s entering pin, receiving payment and receipts etcetera.
What is behavioral design pattern? They are a type of design patterns that generally identify communicating objects.
You may ask, what kind of objects we’re talking about? These objects have common communication patterns between them. While communicating they must realize that patterns.

Continue reading “Chain of responsibility in php”

Decorator Patterns in PHP

When we want to add additional features to our existing classes we generally use decorator pattern.
Do you find this definition useful?
I believe the answer will be NO.
It says about only adding new features. It doesn’t say about how you will use that. Will you add the features by simply hard coding or you’ll add them in the run time.
That’s a pretty big difference.
Why?
Let us consider a simple example where we are talking about a hosting company. A typical hosting company sells hosting services and sometimes they also provide template designing.
Let’s design a pretty basic scenario.

Continue reading “Decorator Patterns in PHP”

Object Oriented Programming and PHP 7

Chapter 1. OOP and PHP 7


For absolute beginners, the term OOP or Object Oriented Programming may seem difficult. Some people want to mystify this term very heavily! Why? Because, the uninitiated PHP developers would never try to make their hands dirty and feet wet with code and will depend on them forever.
So the first step is start believing in your potentials, powers and strength of your mind. Coding is like writing. I show you how easy it is!
Consider a piece of writing where you’re trying to describe a robot. So in your writing ‘robot’ is the subject. In object oriented programming the ‘robot’ is the object. In your piece of writing, your subject ‘robot’ has some descriptions like – the robot has three eyes, two noses, six arms.
In OOP we need to write a class ‘Robot’ which has those properties like this:

//Code/php7book1/index.php
arm = $arms;
        $this->eye = $eyes;
        $this->nose = $noses;
        echo "The robot has {$eyes} eyes, {$noses} noses, {$arms} arms";
    }   
  }
//class ended
$robot = new Robot();
$robot->showRobot(3, 2, 6);

Continue reading “Object Oriented Programming and PHP 7”

How to upgrade to PHP 7


I presume you’re running php 5.x on an Ubuntu 14.04 machine. If you’re windows based, you can easily install Ubuntu 14.04 as a second operating system.
Remember, a genuine php programmer should know a little bit of Linux programming. It’s extremely easy and user friendly. Install Ubuntu on your system and open the terminal by pressing ‘control+alt+t’. For further association with Linux there are tons of free resources available over the internet.
You’ve opened up your terminal; now type this command on it.

sudo add-apt-repository ppa:ondrej/php

A Personal Package Archive, or PPA, is an Apt repository hosted on Launchpad. PPAs allow third-party developers so that they can build and distribute packages for Ubuntu outside of the official channels. They’re often useful sources of beta software – php 7 is also on the developmental stage and it’s not ready for the production environment.

Continue reading “How to upgrade to PHP 7”