Server Side Programming Articles

Page 1050 of 2109

What is PHP Output Buffering?

Alok Prasad
Alok Prasad
Updated on 15-Mar-2026 3K+ Views

Output Buffering is a method to tell the PHP engine to hold the output data before sending it to the browser. As we know PHP sends the output data to the browser in pieces, but if we utilize the output buffering mechanism, the output data is stored in a variable and sent to the browser as one piece at the end of the script. Basic Example Let's demonstrate with a simple example ? string(5) "Hello" string(20) "HelloTutorials Point" How It Works In the above example, ob_get_contents() grabs all of ...

Read More

Compare define() vs const in PHP

Alok Prasad
Alok Prasad
Updated on 15-Mar-2026 5K+ Views

In PHP, both define() and const are used to declare constants, but they have important differences in when and how they can be used. Syntax FOO BAR Key Differences Compile-time vs Runtime Definition The basic difference is that const defines constants at compile time, whereas define() defines them at run time ? Available immediately Available after execution Conditional Definition We can't use const in conditional blocks, while define() allows conditional constant declaration ? This ...

Read More

How to Check if PHP session has already started?

Alok Prasad
Alok Prasad
Updated on 15-Mar-2026 4K+ Views

In PHP, we utilize session_start() to start a session. However, calling this function multiple times in the same script throws an error. Here we will learn how to check if a session has already started without calling session_start() twice. There are two methods to resolve this problem, depending on your PHP version. Method 1: Using session_id() (PHP < 5.4.0) For PHP versions below 5.4.0, use the session_id() function to check if a session exists − The session_id() function returns an empty string if no session has been started, making it perfect for ...

Read More

What are getters and setters methods in PHP?

Alok Prasad
Alok Prasad
Updated on 15-Mar-2026 15K+ Views

In this article, we learn the best way to create getter and setter methods in PHP. Getter and setter methods are utilized when we need to restrict direct access to variables by end−users. Getters and setters are methods used to define or retrieve the values of variables, normally private ones. Just as the name suggests, a getter method is a technique that gets or recovers the value of an object. Also, a setter method is a technique that sets the value of an object. Why Use Private Properties? Let's first understand why direct access to private properties ...

Read More

Explain Polymorphism in PHP.

Alok Prasad
Alok Prasad
Updated on 15-Mar-2026 13K+ Views

Polymorphism is derived from the Greek words "Poly" (meaning many) and "morphism" (meaning forms). In object-oriented programming, polymorphism allows methods in different classes that perform similar functions to share the same interface, enabling code to work with objects of different classes through a common interface. In PHP, polymorphism is implemented using interfaces or abstract classes. This ensures that different classes can be used interchangeably as long as they implement the same contract. Using Interfaces for Polymorphism An interface defines method signatures without implementation. Classes that implement an interface must provide implementations for all methods declared in the ...

Read More

Explain include(),require(),include_once() and require_once() functions in PHP.

Alok Prasad
Alok Prasad
Updated on 15-Mar-2026 5K+ Views

In PHP, file inclusion functions allow you to incorporate external PHP files into your current script. The four main functions − include(), require(), include_once(), and require_once() − serve similar purposes but differ in their error handling and inclusion behavior. include() The include() function includes a specified file. If the file is not found, it generates a warning but continues script execution ? require_once() The require_once() function combines the behavior of require() and the "once" feature. It includes a file only once and generates a fatal error if missing ?

Read More

Convert object to an array in PHP.

Alok Prasad
Alok Prasad
Updated on 15-Mar-2026 9K+ Views

In PHP applications, we often work with data in various formats such as strings, arrays, and objects. Sometimes we need to convert a PHP object to an associative array to process the data more efficiently or to make it compatible with certain functions. An object is an instance of a class that has properties and methods, while an associative array uses string keys to store key−value pairs. Converting objects to arrays allows easier data manipulation and serialization. Using json_encode() and json_decode() The json_encode() function converts a PHP value to JSON string, and json_decode() converts it back to ...

Read More

Comparison of floating point values in PHP.

Alok Prasad
Alok Prasad
Updated on 15-Mar-2026 993 Views

In PHP, testing floating point values for equality is problematic because of how floating point numbers are represented internally. Values that appear identical may not actually be equal due to precision limitations. This article demonstrates the issue and provides solutions for reliable floating point comparison. The Problem Let's examine this issue with a simple example − a and b are not same The else condition executes even though both variables should equal 0.14. This occurs because floating point arithmetic can introduce tiny rounding errors that make direct equality comparison unreliable. ...

Read More

Comparison of dates in PHP

Alok Prasad
Alok Prasad
Updated on 15-Mar-2026 7K+ Views

Comparing two dates in PHP is straightforward when both dates are in a similar format, but PHP may fail to analyze dates when they are in different formats. In this article, we will discuss different approaches to date comparison in PHP using simple operators, the strtotime() function, and the DateTime class. Case 1: Simple Comparison with Same Format You can compare dates using simple comparison operators if the given dates are in the same format ? 2018-11-24 is older than 2019-03-26 Here we declared two dates in the same Y-m-d ...

Read More

imagecolorstotal() function in PHP

Chandu yadav
Chandu yadav
Updated on 15-Mar-2026 109 Views

The imagecolorstotal() function returns the number of colors in an image's palette. This function only works with palette−based images (like GIF or PNG with limited colors), not true color images. Syntax imagecolorstotal($image) Parameters $image − An image resource created by one of the image creation functions like imagecreatefromgif() or imagecreatefrompng(). Return Value Returns the number of colors in the image's palette as an integer. For true color images, it returns 0. ...

Read More
Showing 10491–10500 of 21,090 articles
Advertisements