PHP tips and tricks¶
Contents:
- Duplicate Type
- Yield Or Return
- Multiple Method In Interface
- Operator Overloading
- Three Return Errors
- array_unique() Is Slow
- Cloning Static Variable
- Datetime And Leap Second
- Silent Type Cast
- Objects As Keys In Foreach
- isset() On Uninitialized Properties
- Recycle Generator
- Of Integers And Floats
- max() On Strings
- e And Euler
- Closure On Constructor
- ++ Riddle
- Oversigned Integers
- Local Variable Cost
- Array Items By Value
- Not Set But Exists
- Sorting Enum
- Hypotenuse In Action
- Spaceship Always False
- Inverted Spaceship Results
- isset(), empty() And the Magic Methods
- Comparing Arrays And Object
- Mixed Compatibility
- Where Did The Comma Go?
- Argument Renaming
- When htmlemtities() Is Failing
- Static Arrow Function
- defined() In Action
- expm1() And log1p()
- Is A Class Constant Set?
- preg_split() Magic
- Comparing NAN
- array_unique() And Enum
- Display A Tree Natively
- Speed Up CSV Write To Disk
- php://memory And Maxmemory
- ::parent Operator
- Stuttering PHP
- Riddle:
$this<-code - Multiple Const Types
- Replacing PHP http Wrapper
- Cast But Not A Cast
- Hexadecimal Separator
- Call echo With Commas
- Reusing Decimals For Bananas
- Where To Put The Cast?
- Unpacking A Single Element Array
- Abstract Or Not
- (int) And (ant)
- Cast In Const
- global Overwrites
- Property Hooks And Default Values
- Static And Not Static Method
- intval() And Its Arguments
- Easy Map
- Returning Void
- Casting An Enum Case
- Dynamic Class Constant Edge Cases
- Dynamic Enum Cases
- Yield And Keys
- Array Callback Index
- Time Of Closure Creation
- Coalesce And The Fatal Error
- Weakmap And Enums
- parent In Function
- isset() And The Fatal Error
- All PHP Dereferencements
- No Property Beyond Limits
- Can’t Be Compatible With Less Arguments
- Arrow Functions Import Variables By Values
- Never Is The Lowest Ranking Type
- The Never Function Arrow
- No Rewrite For Exit
- Alias Conflicts
- Not All Incremented Strings Are Deprecated
- get_class() Or ::class?
- No Binding But With Original
- Infinite foreach()
- Who Modifies This Property?
- mixed Is Not No Type
- The Recursive array_merge()
- $GLOBALS Is Not Defined
- Cast Private To Array
- Properties In Interfaces
- Bitwise Operations On String
- Typed Variables
- Type And Reference
- Chaining Spaceship
- parse_str() Edge Cases
- Cast A Closure To Array
- list() Does Not Type
- Triple Plus Operator
- Function Name In A Method
- PHP Quine
- Named Parameter In An Array
- self Is A Valid Type On A Closure
- Keep Interface New Argument Compatible
- Undefined Constant A On Its Line Of Definition
- http_build_query() And Enumerations
- Cannot indirectly modify readonly
- Ellipsis And Coalesce
- namespace namespace
- Namespace, But Far In The Name
- No Hidden Nullable
- Remove Last Item In An Array
- Cancelling Native Function
- Classes Constant Disambiguation With Parenthesis
- compact() Is Recursive
- No Final Parameter
- Is Not A NAN
- Impossible Named Arguments
- func_get_args() Skips Variadic
- Ellipsis With Array Parameters
- Named Parameter Inheritance
- __invoke() On New
- Method Or Property?
- No More Class _
- Method Not Property Name Must Be String
- Static Properties
- The New And The Parenthesis
- Fluent Function
- Cannot Use Isset On Expression, So Use What?
- Constant Redefinition
- No Class Constant In String
- Return Int Not Bool
- By Reference, Error Or Notice?
- Call Function With Strings
- Non Empty Match
- Named Sqlite3 In Memory
- Variable Creation
- All Enum Cases
- Unicode Comments
- Datetime Object, And Years
- Escaping A Regex
- Every Anonymous Class Is Different
- instanceof With Variables
- Undefined Variable
- Compatible Signature
- private Is Relaxed
- Class Implement No More
- Variadic Are Typed And Defaulted
- array_column() To Hash
- \array Was Customizable
- array Is Not An Array
- array_map_assoc() With Keys
- array_map() Goes Full Throttle
- Typed Array
- Initialize Readonly On Child
- Silent Optimisation Of Variables
- Modify String With Array Syntax
- No Force Object To String
- __invoke() Method And Properties
- Constructor Needed
- No Self Referencing Constants
- Deanonymize Class
- Noscream On Ellipsis
- Incompatible Promoted Readonly
- Where Is The Semicolon?
- Self As Attribute
- Reading Micro-seconds
- Promoted Properties Compatibility
- Enum Are Not Linted
- Sorting With Minus
- Override With Interface
- Send An Argument To Generator
- PHP Integer Format
- Compatible Only Interface
- No Cast In Constant Expressions
- Lots Of Silly Arguments
- Child Of Attribute Is Not An Attribute
- Dynamic Class Constant
- The Function Method
- Match() With Multiple Values
- Interfaces Constants Conflicts
- Foreach() Skips Uninitialized Properties
- Casting And Power
- Attribute Without Class
- Class Is A Valid Type
- Float Precision
- Store Float As Index
- Case Insensitive Cast
- $this $this
- No Returntype But Still, Only String
- No Unknown For array_merge()
- No Returntype Enforced
- As As As
- No DNF For Catch
- new On Object
- Unfinished Class Doesn’t Compile
- Yield, Not Return By Reference
- class_exists() With Enums
- No Semicolon In Sight
- glob() With Hidden Files
- A Function Called file_append_contents()
- array_reduce() To Filter And Alter
- $this Is Not Of The Current Class
- Class Constants With Different Types
- No Change To $this
- file_put_contents() With Array Argument
- Get The Generator
- Redefine Native Functions
- A Static Method Cannot Call A Non Static Method
- Declared Before Or After
- Cast Is So Strong
- Roman Loops
- Finally Catches Exception
- Abstract Again
- Always Compatible Variadic
- Yield, Not Return
- try, catch, finally Are All Optional
- null Or Boolean As Array
- Hide Sensitive Parameter
- No Property In Interface
- The Uncallable Function
- Easy Wither Call
- Array Is Full
- Const Without Parenthesis
- Cast Are Case Insensitive
- Array And Object Syntax, Not The Same Error
- When Space Matters
- array array = array()
- Cannot Yield And Never
- Class Invasion Both Ways
- Typed By Enum
- Change A Static Variable Outside Its Function
- Scalar Types Are Unqualified
- array_append() And Short Assignation
- Coalesce And Null
- All Classes Aliases
- Mixed And Untyped Are Not Compatible Types
- Abstract Constants
- Cannot Static Static Property
- More Attribute Usage
- Run Any Script In A Phar
- Static Variable Outside A Method
- Enumeration’s Cases Comparisons
- All Static Curly Syntaxes And One Wrong
- No Such Function As Empty
- Strange –> Operator
- Unexpected Keys In Array
- Recursive Generator
- Documenting Parameters
- Catch Is Optional
- Void Parameter In array_keys()
- Unsetting Properties Surprises
- Multiple Aliases
- Plus Plus Minus Minus
- Constants Can Be Impossible
- Constants Are Mutable
- Quick DTO Or VO Copy
- Stealth Generator
- Quick Serialize
- Clone Clone Clone
- Set readonly Properties Outside The Class
- Exception Polymorphism
- Exponential Minus One
- PHP Infinity Is Reachable
- Negative Squares
- Negating An Assignation
- Numeric Separators Inside A String?
- Identifier Confusions
- Relaxed Syntax With Const
- Closure To Call
- Get $this In A Static
- How To array_intersect_uassoc_insensitive()
- Class And Constant Confusion
- Don’t Forget To Yield
- Inconsistent Constructor Signatures
- foreach() With All The Same Keys
- Battle Of Definition
- Variadic All The Yields
- Refactoring strpos()
- is_a() Versus Instanceof
- Exporting Properties
- Another Cast To Int
ReturnTypeWillChangeIs For All- URL As Comments
- Coalesce And Assignation
- Missing Methods Are Fatal
- Only Initialize With Short Assignation Coalesce
- Keys Are Integers Whenever Possible
- Fast Creation Of stdClass Objects
- An Elephpant In The Code
- Internal Static Call
- strict_types Exceptions
- Playing With Integers Limits
- Signature Compatibility Exception
- Object Is Not A Type
- Forgotten Throw
- Keywords In Namespaces
- No Warning For Unused Variables
- Self In An Interface
- instanceof Object
- stdClass Object
- A Case Of Misplaced Parenthesis
- Checking For Names At Different Times
- Integer Becomes Negative
- Not All Strings In Arrays
- Recursive Arrow Function
- null Does Not Always Equal false
- Recursive Closure
- Cast Precedence
- Enum As A Name
- Type Is Not Always Returned
- The Namespace Stack
- Catch On Interfaces