EDITS.WS

Author: Ignas R.

  • WordPress on VPS: Best Virtualization + How to Optimize Your Site with KVM VPS

    When choosing a virtual private server (VPS) plan, WordPress users must consider its web server and virtualization technology to achieve optimal site speed. At Hostinger, our VPS plans use Kernel-based Virtual Machine (KVM) and OpenLiteSpeed. In this article, we will explain how to optimize WordPress with KVM VPS at Hostinger. In addition, we will discuss […]

    Read More…

    The post WordPress on VPS: Best Virtualization + How to Optimize Your Site with KVM VPS appeared first on Hostinger Tutorials.

  • How to Enqueue Scripts Using wp_enqueue_scripts Hook in WordPress 

    The wp_enqueue_scripts action hook is a vital component of the WordPress development process. Together with the wp_enqueue_script() and wp_enqueue_style() functions, it helps WordPress output content on the website. In this tutorial, we’ll cover the wp_enqueue_scripts action hook along with its complementary functions and provide various use cases to help you improve your WordPress projects. How […]

    Read More…

    The post How to Enqueue Scripts Using wp_enqueue_scripts Hook in WordPress  appeared first on Hostinger Tutorials.

  • How to Enqueue CSS Stylesheet to WordPress Using wp_enqueue_style 

    When developing WordPress themes or plugins, it’s essential to enqueue stylesheets to make them load correctly. To do so, we recommend using the wp_enqueue_style() function. It’s a powerful tool for adding custom stylesheets to your WordPress theme or plugin. This function also ensures that stylesheets are loaded only when necessary and helps avoid conflicts with […]

    Read More…

    The post How to Enqueue CSS Stylesheet to WordPress Using wp_enqueue_style  appeared first on Hostinger Tutorials.

  • Docker Cheat Sheet: All the Most Essential Commands in One Place + Downloadable PDF

    Docker is a popular open-source platform that makes it easy to build, test, deploy, and manage containerized applications in a consistent, portable, or virtual environment. While a powerful tool in your development arsenal, learning the different Docker commands can take time and effort. New users often benefit from having a Docker cheat sheet readily at […]

    Read More…

    The post Docker Cheat Sheet: All the Most Essential Commands in One Place + Downloadable PDF appeared first on Hostinger Tutorials.

  • How to Use the wp_get_attachment_image Function in WordPress + Useful Examples

    The wp_get_attachment_image is a WordPress function that lets you easily retrieve and display image attachments based on their IDs. Whether you’re building a custom theme or a plugin, this function provides a flexible way to display images with custom sizes and attributes. In this tutorial, we’ll go over the wp_get_attachment_image() function and explain its parameters. […]

    Read More…

    The post How to Use the wp_get_attachment_image Function in WordPress + Useful Examples appeared first on Hostinger Tutorials.

  • How to Use wp_update_post to Update WordPress Posts

    Updating posts via the WordPress dashboard is a simple and easy task. However, you can also test out more advanced WordPress features or learn how WordPress functions work during the process. To accomplish this, consider updating posts with the wp_update_post() function. In this tutorial, we will explain the WordPress wp_update_post() function and cover its most […]

    Read More…

    The post How to Use wp_update_post to Update WordPress Posts appeared first on Hostinger Tutorials.

  • What Is the WordPress Loop, How to Use It + Query Loop Block Explained 

    When it comes to developing and hosting a WordPress website, using the Loop can make the process much easier and more streamlined. The WordPress Loop is responsible for fetching and displaying content on your website. In addition, you can use it to customize the content to your liking. In this tutorial, we’ll explain what the […]

    Read More…

    The post What Is the WordPress Loop, How to Use It + Query Loop Block Explained  appeared first on Hostinger Tutorials.

  • tmux Config: Understanding the Configuration File + Customization Examples

    tmux is a popular terminal multiplexer that lets you run multiple sessions inside a single window. What is more, users can easily switch between these sessions, detaching or reattaching them.  Besides features that tmux offers by default, you can customize it further to suit your projects. In this tutorial, we’ll explain how exactly you can […]

    Read More…

    The post tmux Config: Understanding the Configuration File + Customization Examples appeared first on Hostinger Tutorials.

  • How to Fix ERR_QUIC_PROTOCOL_ERROR in Google Chrome: 3 Methods

    Despite being a widely-used web browser, Google Chrome is still prone to errors that can hinder your site’s accessibility. One of them is ERR_QUIC_PROTOCOL_ERROR. Unlike most HTTP status code error messages, it occurs when the browser is unable to reach the web server using the QUIC protocol. Such an error makes your site inaccessible, resulting […]

    Read More…

    The post How to Fix ERR_QUIC_PROTOCOL_ERROR in Google Chrome: 3 Methods appeared first on Hostinger Tutorials.

  • What’s New in PHP 8.2: New Features, Deprecations, and Bug Fixes

    PHP 8.2 is just around the corner. It’s planned to launch on December 8th.

    PHP 8.2 is purely aimed at making developers’ life easier. Most of the changes simplify the coding process and deprecate some of the older functions. It’s always recommended to upgrade to the latest PHP version to maximize your site’s security and get used to the new syntax.

    Let’s look at all the changes that PHP 8.2 is bringing to the table so you can decide if it’s worth making the switch when the new version eventually comes out.

    New PHP 8.2 Features

    In this section, we’ll go over the changes and new features introduced with PHP 8.2.

    New readonly Classes

    The new readonly class property was released with version 8.1. PHP 8.2 improves on it further. Now, you’ll be able to declare a whole class as readonly. Doing so will change all that class’s properties to readonly. This won’t work for dynamic properties – declaring them as readonly will result in an error.

    Declaring the class used to look like this:

    class ReadOnlyClass
    
    {
    
    public readonly int $number,
    
    public readonly int $anotherNumber
    
    }

    With PHP 8.2, the process has been thoroughly simplified:

    class ReadOnlyClass
    
    {
    
    public int $number,
    
    public int $anotherNumber
    
    }

    Keep in mind that it won’t be possible to declare the following PHP features:

    • Enums – since they cannot contain properties at all.
    • Traits.
    • Interfaces.

    Allow true, null, and false as Standalone Types

    With PHP 8.0, users were presented with support for Union Types. You could declare a type as a union of two or more types. Even though you could use false and null as possible types, using them as standalone types was not allowed.

    With PHP 8.2, it will be possible to use false and null as standalone types. With this addition, the PHP type system will be more descriptive as you’ll be able to more accurately declare return, parameter, and property types.

    Redact Sensitive Parameter Value Support

    PHP allows users to track the call stack at any point of the program. It’s extra helpful if you want to debug an application and see why it failed. However, some stack traces contain sensitive information that you may want to mask.

    PHP 8.2 will add a new attribute called SensitiveParameter. It prevents sensitive information from being shown or logged whenever an application runs into trouble. In practice, it will look like this:

    function passwords(
    
    $publicpassword,
    
    #[\SensitiveParameter] $secretpassword
    
    ) {
    
    throw new \Exception('Error');
    
    }
    
    passwords('publicpassword', 'secretpassword');

    New mysqli_execute_query Function and mysqli::execute_query Method

    PHP 8.2 introduces an easier way to handle parameterized MySQLi queries. With the mysqli_execute_query($sql, $params) function and the mysqli::execute_query method, you can prepare, bound, and execute queries within the same function. After successfully running a query, you will be presented with ​​the mysqli_result object.

    RFC’s proposed function looks like this:

    foreach ($db->execute_query('SELECT * FROM user WHERE name LIKE ? AND type_id IN (?, ?)', [$name, $type1, $type2]) as $row) {
    
    print_r($row);
    
    }

    Allow Constants in Traits

    With PHP 8.2, you will be able to declare constants in traits. Until now, traits allowed users to reuse code by defining methods and properties. Now it will be possible to declare constants in traits as well.

    Here’s an official RFC proposal example:

    trait Foo {
    
    public const FLAG_1 = 1;
    
    protected const FLAG_2 = 2;
    
    private const FLAG_3 = 2;
    
    public function doFoo(int $flags): void {
    
    if ($flags & self::FLAG_1) {
    
    echo 'Got flag 1';
    
    }
    
    if ($flags & self::FLAG_2) {
    
    echo 'Got flag 2';
    
    }
    
    if ($flags & self::FLAG_3) {
    
    echo 'Got flag 3';
    
    }
    
    }
    
    }

    New Disjunctive Normal Form (DNF) Types

    With PHP 8.2, you will be able to use a new Disjunctive Normal Form (DNF) types feature. It is a standardized way of organizing boolean expressions. To be exact, it consists of a disjunction of conjunctions or simply boolean OR of ANDs.

    An RFC proposal example can be found below:

    // Accepts an object that implements both A and B,
    
    // OR an object that implements D.
    
    (A&B)|D
    
    // Accepts an object that implements C,
    
    // OR a child of X that also implements D,
    
    // OR null.
    
    C|(X&D)|null
    
    // Accepts an object that implements all three of A, B, and D,
    
    // OR an int,
    
    // OR null.
    
    (A&B&D)|int|null

    AllowDynamicProperties Attribute

    PHP 8.2 will deprecate dynamic variables in classes. This will result in a deprecation message in PHP 8.2 and ErrorException in future versions of PHP.

    For this reason, a new #[AllowDynamicProperties] attribute will be added to PHP 8.2 in order to allow dynamic properties for classes. An RFC example looks like this:

    class Foo {}
    
    $foo = new Foo;
    
    // Deprecated: Creation of dynamic property Foo::$bar is deprecated
    
    $foo->bar = 1;
    
    // No deprecation warning: Dynamic property already exists.
    
    $foo->bar = 2;

    Deprecated Features in PHP 8.2

    In this section, we’ll look at all the features that will be deprecated in PHP 8.2.

    #utf8_encode() and utf8_decode() Functions

    utf8_encode() and utf8_decode()functions are used to convert between ISO-8859-1 and UTF-8 encoding standards. Due to a lack of error messages, warnings, and limited encoding support, PHP 8.2 will deprecate these functions while PHP 9.0 will exclude them entirely. Alternatively, users will be able to use iconv or intl extensions to convert the encoding standard.

    Mbstring: Base64, Uuencode, QPrint, and HTML Entity Encodings

    Mbstring is used to convert to and from several character encoding standards such as UTF-8/16/32 and ISO-8859-1. It also includes support for Base64, Quoted-Printable, Uuencode, and HTML Entities.

    However, these formats process information in raw bytes instead of sequences of bytes. It’s also worth noting that PHP already has separate functions to encode/decode these formats. Thus, PHP 8.2 will deprecate the mbstring extension with the following labeled encodings:

    • BASE64
    • UUENCODE
    • HTML-ENTITIES
    • html (alias of HTML-ENTITIES)
    • Quoted-Printable
    • qprint (alias of Quoted-Printable)

    Partially-Supported Callables

    PHP 8.2 will deprecate partially-supported callables that don’t work with the $callable() pattern. The list of deprecated callables can be found below:

    $callable = "self::method";
    $callable = "parent::method";
    $callable = "static::method";
    $callable = ["self", "method"];
    $callable = ["parent", "method"];
    $callable = ["static", "method"];
    $callable = ["MyClass", "MyParentClass::myMethod"];
    $callable = [new MyClass(), "MyOtherClass::myMethod"];

    To prevent the deprecation message, users can convert all self, parent, and static keywords to their corresponding class names.

    ${var} String Interpolation

    PHP allows users to replace variable values within a string literal with double quotes, as in the following examples:

    • “$myname” – directly embedding variables.
    • “{$myname}” – braces outside the variable.
    • “${myname}” – braces after the dollar sign.
    • ” ${expr}” – variable variables equivalent to using (string) ${expr}

    While offering the same functionality, the syntax of the last two options is quite complex. That’s why they will be deprecated in PHP 8.2. You’ll still be able to use the first two options without any issues.

    Other PHP 8.2 Changes

    Random Extension Improvement

    PHP offers a number of functions for random number generation. With PHP 8.2, some of them will be moved to a new random extension. This extension will be included in PHP by default, and there won’t be an option to disable it.

    Here’s a list of all the functions and constants that will be moved to the random extension. Keep in mind that they will remain in the global namespace.

    MySQLi No Longer Supports libmysql

    Historically PHP supported two libraries to connect MySQL databases: mysqlnd and libmysql. Since PHP 5.4, the default recommended library has been mysqlnd. In order to simplify PHP code testing, it was decided to remove libmysql with PHP 8.2.

    From now on, you’ll need to use the mysqlnd library to connect MySQL databases.

    Sort Order Changes for the ksort Function

    The ksort function sorts an array by key in ascending order. PHP 8.2 will introduce a bug fix to make the output of the SORT_REGULAR parameter consistent with the other parameters. Up until PHP 8.2, it prioritized alphabetic keys before numeric keys.

    Now, ksort will place numeric keys before alphabetic keys when sorting. In practice, sorted keys will look like this:

    ["1" => '', "2" => '', "a" => '', , "b" => ''];

    Instead of:

    ["a" => '', "b" => '', "1" => '', , "2" => ''];

    The str_split Function Returns Empty Arrays for Empty Strings

    Another bug fix is meant for the str_split function. It is used to split a string into an array.

    Up until PHP 8.2, if this function was given an empty string, it would also return an empty string. PHP 8.2 introduces a fix to this bug, and str_split will return an empty array if given an empty string.

    How to Change the PHP Version

    Usually, hosting providers offer you an easy way to switch between PHP versions. If you’re using Hostinger’s hPanel, all you need to do is select your hosting plan and search for PHP Configuration:

    PHP Configuration search results on hPanel. It shows the PHP Configuration section on the side bar

    Here, you will find all of the latest stable versions of PHP. Select the preferred version and press Update to save the changes.

    PHP Configuration page, here, users can change the PHP version and manage PHP extensions or options

    Within this utility, It’s also possible to manage PHP extensions and PHP options for all versions individually.

    Conclusion

    PHP 8.2 offers many improvements over the previous versions. It introduces a number of new features like new readonly classes, deprecates several outdated implementations with complex syntax, and fixes important bugs to streamline the development workflow and make using PHP easier.

    We hope this post has helped you prepare for the upcoming PHP 8.2 launch. We’re eagerly looking forward to the new version’s full release on December 8th!

    The post What’s New in PHP 8.2: New Features, Deprecations, and Bug Fixes appeared first on Hostinger Blog.