"Mr Branding" is a blog based on RSS for everything related to website branding and website design, it collects its posts from many sites in order to facilitate the updating to the latest technology.
To suggest any source, please contact me: Taha.baba@consultant.com
Thursday, March 12, 2020
Apple Says Using Disinfectant Wipes on Phones is OK Amid Coronavirus Concerns
[ This is a content summary only. Visit our website https://ift.tt/1b4YgHQ for full links, other content, and more! ]
by Zia Muhammad via Digital Information World
Wednesday, March 11, 2020
Facebook experiments with cross-platform of Stories
[ This is a content summary only. Visit our website https://ift.tt/1b4YgHQ for full links, other content, and more! ]
by Saima Salim via Digital Information World
Sensor Tower’s VPNs and Ad Blockers Are Quietly Collecting Your Data
[ This is a content summary only. Visit our website https://ift.tt/1b4YgHQ for full links, other content, and more! ]
by Zia Muhammad via Digital Information World
Google Maps gets Lens integration
[ This is a content summary only. Visit our website https://ift.tt/1b4YgHQ for full links, other content, and more! ]
by Saima Salim via Digital Information World
PHP Magic Methods Cheatsheet
In this post, I'll give you a cheetsheet quick reference to all the magic methods available in PHP.
Whether you are a seasoned PHP developer or a novice in PHP development, if you’ve worked with OOP in PHP, then you’re using at least a couple of PHP magic methods already. However, if you have not heard of PHP magic methods yet, let me introduce them:
The function names __construct(), __destruct(), __call(), __callStatic(), __get(), __set(), __isset(), __unset(), __sleep(), __wakeup(), __toString(), __invoke(), __set_state(), __clone() and __debugInfo() are magical in PHP classes. You cannot have functions with these names in any of your classes unless you want the magic functionality associated with them. All magic methods MUST be declared as public.
If you’re wondering why these methods are called magic methods, it’s because of the fact that if you define one of these methods in your class, it’ll be called automatically and you are just supposed to define what should happen within it. The best example of the magic method is the __construct()
function which is called automatically when the object is instantiated.
In general, magic methods in PHP allow you to perform various kinds of operations with objects. It also allows you to handle certain kinds of situations by manipulating objects.
PHP Magic Methods
The aim of this article is to go through all the magic methods in PHP and explain them each briefly.
The __contruct()
Method
If you define this method in your class, it’ll be called automatically when an object is instantiated. The purpose of this method is to assign some default values to object properties. This method is also called a constructor.
Let’s have a look at a quick example to understand how it works:
<?php class Student { private $name; private $email; public function __construct($name, $email) { $this->name = $name; $this->email = $email; } } $objStudent = new Student('John', 'john@tutsplus.com'); ?>
In the above example, when you instantiate a new object by with new student('John','
john@tutsplus.com
')
, it calls the __construct()
method in the first place. In the __construct()
method, we’ve assigned values passed in the arguments to the object properties.
The __destruct()
Method
The __destruct()
method is called a destructor and it’s called when the object is destroyed. Generally, it’s also called when the script is stopped or exited. The purpose of this method is to provide an opportunity to save the object state or any other cleanups you would want to perform.
Let’s have a look at the following example:
<?php class Student { private $name; private $email; public function __construct($name, $email) { $this->name = $name; $this->email = $email; } public function __destruct() { echo 'This will be called when the script is shut down...'; // save object state/other clean ups } } $objStudent = new Student('John', 'john@tutsplus.com'); ?>
The __set()
Method
The __set()
magic method is called when you try to set data to inaccessible or non-existing object properties. The purpose of this method is to set extra object data for which you haven’t defined object properties explicitly.
Let’s get back to our example to understand how it works.
<?php class Student { private $data = array(); public function __set($name, $value) { $this->data[$name] = $value; } } $objStudent = new Student(); // __set() called $objStudent->phone = '0491 570 156'; ?>
As you can see in the above example, we’re trying to set the phone
property which is non-existent. And thus, the __set()
method is called. The first argument of the __set()
method is the name of the property which is being accessed and the second argument is the value we’re trying to set.
The __get()
Method
In the case of the __set()
method example in the previous section, we discussed how to set values for non-existent properties. The __get()
method is exactly the opposite of it. The __get()
magic method is called when you try to read data from inaccessible or non-existing object properties. The purpose of this method is to provide values to such properties.
Let’s see how it works in action.
<?php class Student { private $data = array(); public function __set($name, $value) { $this->data[$name] = $value; } public function __get($name) { If (isset($this->data[$name])) { return $this->data[$name]; } } } $objStudent = new Student(); // __set() called $objStudent->phone = '0491 570 156'; // __get() called echo $objStudent->phone; ?>
The __toString()
Method
The __toString()
magic method allows you to define what you would like to display when an object of the class is treated like a string. If you use echo
or print
on your object, and you haven’t defined the __toString()
method, it’ll give an error.
Let’s try to understand it with the following example.
<?php class Student { private $name; private $email; public function __construct($name, $email) { $this->name = $name; $this->email = $email; } public function __toString() { return 'Student name: '.$this->name . '<br>' . 'Student email: '.$this->email; } } $objStudent = new Student('John', 'john@tutsplus.com'); echo $objStudent; ?>
In the above example, when you echo the $objStudent
object, it’ll call the __toString()
method. And in that method, you can decide what you would like to display. If you hadn’t defined the __toString()
method, this would have resulted in an error!
The __call()
and __callStatic()
Methods
If __get()
and __set()
methods are called when you’re dealing with non-existent properties, the __call()
method is called when you’re trying to invoke inaccessible methods, the methods that you haven’t defined in your class.
<?php class Student { public function __call($methodName, $arguments) { // $methodName = getStudentDetails // $arguments = array('1') } } $objStudent = new Student(); $objStudent->getStudentDetails(1); ?>
As you can see, we’ve called the method getStudentDetails
which is not defined, and thus the __call()
magic method is called. The first argument is the name of the method being called and the second argument is an array of arguments that were passed in that method.
The __callStatic()
method is very similar to the __call()
method with the only exception is that it’s called when you’re trying to invoke inaccessible methods in a static context. So if you’re trying to access any static method which is not defined, the __callStatic()
function will be called.
The __isset()
and __unset()
Methods
The __isset()
magic method is called when you call the isset()
method on inaccessible or non-existing object properties. Let’s see how it works through an example.
<?php class Student { private $data = array(); public function __isset($name) { return isset($this->data[$name]); } } $objStudent = new Student(); echo isset($objStudent->phone); ?>
In the above example, the phone property is not defined in the class, and thus it’ll call the __isset()
method.
On the other hand, the __unset()
is a method called when you call the unset()
method on inaccessible or non-existing object properties.
The __sleep()
and __wakeup()
Methods
The __sleep()
magic method is different compared to methods that we’ve discussed so far. It’s called when you call the serialize()
function on the object. In case of a very large object, you only want to save selected properties during serialization, and clean up the object. The __sleep()
method must return an array with the names of all properties of the object that should be serialized.
Again, let’s revise our example to see how it works.
<?php class Student { private $name; private $email; private $phone; private $db_connection_link; public function __construct($name, $email, $phone) { $this->name = $name; $this->email = $email; $this->phone = $phone; } public function __sleep() { return array('name', 'email', 'phone'); } public function __wakeup() { $this->db_connection_link = your_db_connection_function(); } } ?>
In the above example, when you serialize()
the Student
object, it’ll call the __sleep()
method and it’ll only preserve the values of name
, email
and phone
variables.
On the other hand, the use of the __wakeup()
magic method is to reestablish any connections and start up tasks when the unserialize()
function is called on the object.
The __invoke()
Method
The __invoke()
magic method is a special method which is called when you try to call an object as if it was a function. Firstly, let’s see how it works and then we’ll see the purpose of this magic method.
<?php class Student { private $name; private $email; public function __construct($name, $email) { $this->name = $name; $this->email = $email; } public function __invoke() { echo 'Student object is called as a function!'; } } $objStudent = new Student('John', 'john@tutsplus.com'); $objStudent(); ?>
As you can see, the $objStudent
object is treated as if it was a function, and as we’ve defined the __invoke()
method, it’ll be called instead of giving you an error. The main purpose of the __invoke()
method is that if you want to treat your objects as callable, you can implement this method.
The __clone()
Method
If you want to duplicate an existing object, you could use the clone
keyword to do that. But after cloning, if you want to modify properties of the cloned object, you can define the __clone()
magic method in your class.
<?php Class Student_School { } class Student { private $name; private $email; private $object_student_school; public function __construct() { $this->object_student_school = new Student_School(); } public function __clone() { $this->object_student_school = clone $this->object_student_school; } } $objStudentOne = new Student(); $objStudentTwo = clone $objStudentOne; ?>
The issue with the above approach is that it makes a shallow copy of the object while cloning, and thus internal objects of the cloned object will not be cloned.
In the context of the above example, if you wouldn’t have defined the __clone()
method, the cloned object, $objStudentTwo
, would still point to the same Student_School
object referenced by the $objStudentOne
object. Thus, by implementing the __clone()
method, we make sure that the Student_School
object is cloned as well along with the main object.
The __debugInfo()
Method
The __debugInfo()
magic method is called when you try to dump any object by the var_dump()
function. If you haven’t defined this method in your class, it’ll dump all public, private and protected properties. So if you want to restrict the information which is displayed while dumping, you can use this method.
<?php class Student { public $name; private $email; private $ssn; public function __debugInfo() { return array('student_name' => $this->name); } } $objStudent = new Student(); var_dump($objStudent); // object(Student)#1 (1) { ["student_name"]=> NULL } ?>
This method should return an array of key, value pairs which will be displayed when the var_dump()
function is called on the object. As you can see, you can completely control what you want to display when the object will be dumped with the var_dump()
function.
The __set_state()
Method
The __set_state()
method is a static method which is used in conjunction with the var_export()
function. The var_export()
function outputs a structured information about a variable. When you use this function to export classes, you need to define the __set_state()
method in your class.
<?php class Student { public $name; private $email; public function __construct($name, $email) { $this->name = $name; $this->email = $email; } public static function __set_state(array $array) { $obj = new Student; $obj->name = $array['name']; $obj->email = $array['email']; return $obj; } } $objStudent = new Student('John','John@yahoo.com'); var_export($objStudent); // Output: Student::__set_state(array( 'name' => 'John', 'email' => 'John@yahoo.com', )) ?>
As you can see, the exported string is a valid PHP code and you can use it to restore the original object.
Conclusion
In this article, we’ve gone through all the magic methods available in PHP. For every method, I provided a short but meaningful example which should help you to understand the purpose of it. And I hope you could use this article as a quick reference or a cheatsheet in your day-to-day PHP development.
The Best PHP Scripts on CodeCanyon
Explore thousands of the best and most useful PHP scripts ever created on CodeCanyon. With a low-cost one time payment, you can purchase these high-quality WordPress themes and improve your website experience for you and your visitors.
Here are a few of the best-selling and up-and-coming PHP scripts available on CodeCanyon for 2020.
-
PHP14 Best PHP Event Calendar and Booking ScriptsKyle Sloka-Frey
-
PHP10 Best PHP URL Shortener ScriptsMonty Shokeen
-
PHP12 Best Contact Form PHP Scripts for 2020Esther Vaati
-
PHPComparing the 5 Best PHP Form BuildersNona Blackman
-
PHPCreate Beautiful Forms With PHP Form BuilderAshraff Hathibelagal
by Sajal Soni via Envato Tuts+ Code
5 Best Free WordPress Hosting Providers for 2020
Are you looking for someone to host your WordPress website, but aren’t sure whether free or premium hosting is right for you?
If your website is going to be a success, then you need the right hosting provider—after all, there are countless companies who can help run your website, but a reliable, secure and scalable WordPress hosting provider can help improve your website.
In this article, we’ll be taking a look at 5 WordPress hosting providers that can help you create and host a successful WordPress website for free.
Fast and Easy WordPress Hosting With SiteGround
And if you decide that you need performance and support for your WordPress site that isn't available for free, I'll also introduce you SiteGround, our recommendation for paid WordPress hosting.
Thanks to Envato's partnership with SiteGround, you can get up to 70% off managed WordPress hosting.
What Are the Benefits of Free WordPress Hosting?
There’s one major reason why so many people choose free WordPress hosting over premium hosting, and the clue’s in the name: free WordPress hosting is free.
Since you don’t have to pay any upfront costs, free WordPress hosting is ideal if you’re on a budget, or if you want to test drive a few ideas before committing to a paid hosting subscription. If you’re new to WordPress, then free hosting can also help you decide whether WordPress is right for you, by giving you some hands-on experience with the platform.
Finally, if you don’t have any plans to monetize your website, then free hosting can be a way to indulge in your love of blogging, without having to pay for the privilege.
The Drawbacks to Free WordPress Hosting
Every free WordPress hosting provider has their own unique strengths and weaknesses. However, if you opt for free WordPress hosting then you should expect to encounter some, or all of the following limitations.
Traffic, Storage and MySQL Restrictions
Free hosting providers often restrict their servers, which means your website may struggle to handle large volumes of traffic. Some hosting providers will also place restrictions on disk space, database size, and the total number of MySQL connections that you can operate at any one time.
These restrictions are often designed with upselling in mind, as many free hosting providers also offer unrestricted premium services. Over time, your website may outgrow its free hosting plan, at which point you’ll have no choice but to upgrade to a paid offering.
Tougher Terms and Conditions
Regardless of whether you opt for premium or free hosting, most providers have Terms and Conditions that specify how you can and can’t use their services. If you violate these terms, then your provider may suspend your account, or even delete your website and all of its content entirely.
Most of the time these restrictions are understandable, for example the vast majority of free and premium WordPress providers won’t host a website that promotes illegal substances or activities. However, free hosting providers tend to be pickier about the type of content they allow, and may sometimes take issue with content that doesn’t strike you as particularly controversial, for example banning websites that promote any kind of competition or contest.
To avoid losing access to your WordPress website and potentially all of your content and data, it’s vital that you review your provider’s Terms and Conditions carefully.
Upselling Emails and Third-Party Spam
Free hosting providers need to earn a living too, and one popular method is encouraging users to upgrade to a premium package.
While the occasional marketing email is a small price to pay for free WordPress hosting, some companies take things too far, and you may find yourself receiving regular unsolicited emails. These emails can range from blatant adverts for premium products and services, to more subtle upselling initiatives, for example emails encouraging you to check out the provider’s latest blog post, download their new ebook or sign up for their free webinar.
You should also be aware that if you’re not paying for a product, then you are the product, so there’s a chance your provider may sell your information to a third party. If you opt for a reputable WordPress provider then in theory you shouldn’t receive any third party spam, but it’s important to note that gathering and selling data is a popular way for companies to monetize their free products and services.
You’re Not a Paying Customer
When it comes to WordPress hosting, free doesn’t necessarily mean bad.
All the companies mentioned in this article have great community feedback, and provide all the features you need to create and maintain a successful WordPress website.
Many free hosting providers also offer premium plans, so their business model relies on free users upgrading to one of their premium hosting packages, so they have an incentive to keep their free users happy.
However, despite all these points you’re never going to have the same leverage as a paying customer. If your requirements aren’t being met or you’re unhappy with the service, then you can file a support ticket, make a complaint or leave the provider a negative review, but you can't threaten the one thing that all companies fear the most: that a paying customer will take their business elsewhere.
Free WordPress Hosting: 5 Options Compared
Despite the potential drawbacks, free WordPress hosting is one of the quickest and easiest ways to create a WordPress website.
To help get your website off to the best possible start, let’s take an in-depth look at 5 places where you can host your WordPress website, for free.
-
WordPress.com
Let’s get the obvious out of the way first: WordPress.com is a free hosting service created by the co-founder of WordPress.
Rather than splashing out on your own hosting solution, you can head over to WordPress.com, click Get started, complete a few forms, and your website will be ready to go.
WordPress.com is a quick, easy and convenient solution that offers robust security and reliable performance, regardless of how many people visit your website. If you use WordPress.com as your provider, then you also won’t have to worry about manually installing any updates or creating backups, as all of this is managed automatically.
Before you jump in, there are some restrictions you need to be aware of:
- You cannot sell advertising space on your website... This severely limits your options when it comes to generating revenue, especially since you can’t monetize your website by adding membership functionality, or eCommerce features.
- ...but WordPress can! WordPress has the right to place adverts on your website. You have no control over which adverts WordPress chooses to display, and you won’t receive any of the revenue generated by these ads.
- You can’t upload plugins. The huge community of third party plugins is one of WordPress’ biggest strengths, allowing you to add all sorts of powerful, innovative and niche features to your website. If you opt for WordPress.com, then you won’t be able to use any of these plugins, unless you purchase an additional plan or shell out for the WordPress.com VIP program.
- Limited storage space. A free account comes with 3GB of storage, but you’ll need to upgrade to a paid plan if you require more than 3GB.
- You can only use the provided themes. WordPress.com doesn’t support custom themes, so you’ll be limited to WordPress’ collection of free themes.
- A lack of support for third party tracking platforms. WordPress has a built-in Stats page that displays some basic information, such as the total number of people who’ve visited your site. However, WordPress.com doesn’t support third party tracking tools, so you can’t get a deeper insight by installing tools such as Google Analytics.
- You cannot remove the WordPress disclaimer. By default, your website will feature a Powered By WordPress message in its footer. Although you can remove this disclaimer on WordPress.org, it’s a permanent fixture on WordPress.com.
- You can only use a WordPress-branded domain. When you create your website using WordPress, its URL must contain WordPress.com, for example mywebsite.wordpress.com. Unless you purchase a custom domain name, you’re stuck with this WordPress branding!
2. 000Webhost: 99% Uptime and 300MB of Disk Space
Compared to many other free hosting services, 000WebHost has very few limitations and offers an impressive set of features.
For the grand total of $0, you’ll get access to a website builder, a one-click WordPress installer, 300MB of disk space, and free domain hosting that supports the latest versions of PHP and MySQL. According to the 000WebHost website, they also have proven 99% uptime and a dedicated admin team who’ll be on-hand to ensure your website is running smoothly.
However, there are some restrictions. To make it more difficult for spammers to abuse the platform, 000Webhost limits the number of concurrent MySQL connections to 30 connections per database. Your database is also limited to 1GB, and a maximum of 100 tables.
For most WordPress users, these limitations shouldn’t be an issue, however if you use a large number of plugins then there’s a chance your web pages will be slow to load, or they may even throw a 502 Bad Gateway error.
The following plugins are also known to cause Error 500:
- W3 Total Cache
- WP Speed of Light
- WP Fastest Cache
- WP Performance Score Booster
3. ByetHost's Clustered Hosting Network
ByetHost provides free and premium hosting to over 1,000,000 websites.
If you opt for ByetHost’s free services, then you’ll get 5GB of disk space, an FTP account and File Manager, unlimited Addon domains, parked domains and subdomains, plus automatic HTTPS SSL.
You’ll also get access to ByetHost’s own VistaPanel control panel, and the Softaculous application, which can install over 333 scripts, including PHPbb3, Zen-Cart, osCommerce, MyBB, MyLittle Forum, 4images, Coppermine, SMF, and Joomla. To boost performance, ByetHost spreads your website’s traffic across multiple servers simultaneously, by maintaining their own clustered hosting network.
However, ByetHost only provides self-signed SSL certificates, so anyone who visits your website will receive a security warning unless they explicitly trust your site. With security a major concern for many Internet users, this warning can have a negative impact on how many people actually click through to your website.
4. AwardSpace: Access to Custom "Zacky" Tools
AwardSpace has a number of pricing plans, but they also offer free WordPress hosting.
If you opt for their free plan, then you’ll get access to:
- One free domain. You can choose from a free dx.am domain plus a long list of free subdomains, although if you want a .com domain then you’ll need to upgrade to one of AwardSpace’s premium hosting plans.
- up to three subdomains
- 5GB of bandwidth
- 1GB of disk space
- access to the same high-speed network as AwardSpace’s paying clients
- MySQL database support
- a one-click Zacky Installer
- AwardSpace’s Zacky Website Builder, which lets you build a website with no coding
- access to AwardSpace’s custom hosting control panel
- web-based File Manager for easier uploads
- protection against hackers, spammers and other digital threats, with a built-in firewall and ClamAV anti-virus software
- No ads. In the Terms and Conditions, AwardSpace explicitly states that they will never force you to place ads on your website.
- 24/7 customer support
As always, there are some drawbacks:
- There’s no guarantee that you’ll be able to renew your domain successfully, even if you pay for AwardSpace’s domain renewal service.
- For security reasons, all outgoing connections are disabled.
- You’re responsible for backing up your own data.
- There’s a maximum upload file limit of 15MB, and some file types are unsupported, including MP3, .exe, Torrent, ZIP, .gz and .tgz.
- If your website doesn’t receive any traffic for 12 months, then your account will be marked as inactive and may be deleted.
- You’re limited to a single MySQL Database with a maximum 30MB of space. You’re also restricted to 12,000 MySQl queries per hour, and a maximum of 30 concurrent connections.
5. WPNode: DDoS and CloudFlare protection
WPNode offers free domain and subdomain hosting with no ads, 1GB of SSD storage, and unlimited data transfer.
To protect your website against Denial-of-service (DDoS) attacks, WPNode uses CloudFlare and hides your wp-config.php file, so your information isn’t easily accessible to hackers. If you choose WPNode as your hosting provider, then your website will also be protected by a built-in firewall, malware detection, patch management, and reputation management.
WPNode offers 24/7 support to all their customers, and their website makes the impressive claim that if you contact them via their support ticketing system then you can expect a response within minutes.
Onto the negatives, and the WPNode staff manually verify each and every signup, which can take up to 10 hours, so you may not be able to start using your WordPress website straight away.
WPNode will backup your content, but only once per week. To make sure that you never lose an entire week’s worth of content and data, it’s recommended that you perform your own manual backups, in addition to WPNode’s scheduled backups.
Removing Restrictions, With Premium WordPress Hosting
As we’ve seen in this article, all free hosting providers have their own unique strengths and weaknesses.
If you know exactly what you want from a hosting provider, then you should be able to find a free provider who meets most (if not all) of your requirements. However, if you’re creating a website for your business, have plans to monetize your content, or have long-term plans to grow your website, then it makes more sense to invest in premium WordPress hosting.
Premium hosting providers don’t typically place any major restrictions on traffic and storage, and give you more options for monetizing your content.
Interested in premium WordPress hosting? SiteGround provides premium hosting to over 2,000,000 domains, including a managed WordPress hosting service that’s officially recommended by WordPress.org. Best of all, our partnership with SiteGround means that you can get reliable, easy to use WordPress hosting for up to 70% off!
Some of SiteGround’s notable features include:
Automated WordPress Installation
Why go to the effort of downloading, installing and configuring WordPress manually, when you can take advantage of SiteGround’s click-and-install solution? SiteGround’s WordPress Starter tool provides easy access to a portfolio of professional website designs and key functionalities that you can add to your site, including online stores and contact forms.
SiteGround Migrator Plugin
If you have an existing website, then you can securely migrate all of your content to SiteGround while keeping your configuration intact.
Protection Against Security Vulnerabilities and Exploits
SiteGround manages the overall security of your application at the server and firewall level, and they’re continuously adding rules that can help protect your website against new and emerging threats.
A Faster, More Reliable Website
SiteGround is hosted on the powerful Google Cloud platform. In addition, SiteGround uses NGINX Direct Delivery, the SuperCacher service, Memcached, and the CloudFlare Content Delivery Network (CDN) to improve your website’s loading speeds.
Automatic Updates
SiteGround can update all of your plugins and your WordPress software automatically, so you’ll always have access to the latest bug fixes, patches and features.
Want to learn more? Explore SiteGround’s various WordPress hosting solutions!
Conclusion
In this article, we explored some of the most popular free WordPress hosting services that you can start using today.
Free WordPress hosting can be a quick, convenient and affordable option for many websites, but there are some scenarios where free hosting may not be the best fit. To help you decide whether this kind of hosting is right for you, we also covered some of the most common drawbacks associated with free hosting, and introduced a premium alternative that you may want to try.
Do you have any more recommendations for free WordPress hosting? If your favourite provider didn’t feature in this article, then be sure to leave your recommendations in the comments below!
by Jessica Thornsby via Envato Tuts+ Code
Android lose more value than iPhone - What to buy now?
[ This is a content summary only. Visit our website https://ift.tt/1b4YgHQ for full links, other content, and more! ]
by aqsqa qadir via Digital Information World