All articles
Every article published on Guilty Of PHP
43 articles
-
Understand PHP execution and behavior
Find PHP Built-In Functions in the Manual and Your Runtime
Browse documented functions by name or reference section, then print the internal functions and loaded extensions in the PHP runtime you need to inspect.
-
Define a PHP Function That Takes Arguments and Returns a Value
Build a reusable line-total calculation, then follow two calls from their supplied numbers through the function and back to the caller.
-
Trim, Search, and Replace Text in a PHP String
Follow one ASCII string from trimming and a byte-length check through a position-aware search and replacement of both matching terms.
-
Declare a Readonly PHP Class Without Invalid Properties
Use a typed data holder to check declarations, inheritance, traits and writes before converting an existing class.
-
Define a PHP Abstract Class with a Shared Method and Required Child Method
Build a Label parent that prints a value, then give two concrete children their own values without duplicating the printing method.
-
Autoload MyApp\Catalog\Product from src/ with SPL or Composer
Map one namespaced class to its file with an SPL callback, then make the same mapping in Composer and include its generated autoloader.
-
Can You Declare a Named Class Inside Another PHP Class?
PHP does not support named nested class declarations. Declare the helper separately and pass an instance to the class that uses it.
-
Can a PHP Class Extend Two Classes? Use Interfaces, Traits, or Composition
A class gets one parent, but it can satisfy multiple contracts, reuse a trait method, and call another object for a separate service.
-
Create a PHP Class and Call Its Method on Two Objects
Define one Greeting class, give two instances different names, and trace how the same method reads each object's property.
-
Pass a One-Off PHP Object to a Function That Expects an Interface
Create an anonymous Formatter directly in a function call, pass it constructor arguments, and extend a base class when it needs a protected helper.
