Post by account_disabled on Mar 9, 2024 8:09:26 GMT
Constants in Traits Traits have been with us since PHP .. They have long been the answer to inheritance composition. Traits now get an interesting new feature the ability to define constants in a trait. trait MyTrait private const MY_CONSTANT Now if your trait uses a constant you can define it in the trait and not have to remember to define it in every class that uses the trait. trait MyTrait private const MY_CONSTANT public function meaningOfLife int return selfMY_CONSTANT class MyClass use MyTrait myObj new MyClass echo myObjmeaningOfLife prints Like everything in life there are some rules. Traits can define class constants. If a class uses that trait it can also define the same class constant as long as both the visibility and the value are exactly the same . So the above example works but the following one will trigger a fatal error.
Trait MyTrait private const MY_CONSTANT public function meaningOfLife int return Portugal Mobile Number List selfMY_CONSTANT class MyClass use MyTrait public const MY_CONSTANT Still even with the rules you have to follow this is a real step forward. Traits are a great way to share code between classes and are now even more selfcontained. Random Extension .x Random Extension Improvement The original PHP random number generator is still in the codebase. It has never been great and is absolutely useless for crypto uses. In PHP we got a couple of new functions random_int and random_bytes . They went a long way to fix the problems but under the hood they are just interfaces to the native operating systems random number generator. At the time this was a good solution but the problem is that it is slow. Now with PHP . we not only get a completely new random number generator but its built into PHP and we get an extensible objectoriented interface. RFCs that Im lumping together. After voting and approving the first Random Extension .
It turned out that there were some problems with it. A second RFC Random Extension Improvement was prepared and voted on to address the problems found with the first. The end result is a new set of classes that gives us better pseudorandom numbers in PHP. While we are getting several new random number generators RNGs for simplicity Ill talk about the new RandomEngineSecure class . engine new RandomEngineSecure randomString enginegenerate a random binary string echo binhexrandomString Now if we want to do something like sort an array we need one of the new Randomizer objects. randomizer new RandomRandomizerengine items range randomizedItems randomizershuffleArrayitems print_rrandomizedItems In the example above we use the Secure engine.
Trait MyTrait private const MY_CONSTANT public function meaningOfLife int return Portugal Mobile Number List selfMY_CONSTANT class MyClass use MyTrait public const MY_CONSTANT Still even with the rules you have to follow this is a real step forward. Traits are a great way to share code between classes and are now even more selfcontained. Random Extension .x Random Extension Improvement The original PHP random number generator is still in the codebase. It has never been great and is absolutely useless for crypto uses. In PHP we got a couple of new functions random_int and random_bytes . They went a long way to fix the problems but under the hood they are just interfaces to the native operating systems random number generator. At the time this was a good solution but the problem is that it is slow. Now with PHP . we not only get a completely new random number generator but its built into PHP and we get an extensible objectoriented interface. RFCs that Im lumping together. After voting and approving the first Random Extension .
It turned out that there were some problems with it. A second RFC Random Extension Improvement was prepared and voted on to address the problems found with the first. The end result is a new set of classes that gives us better pseudorandom numbers in PHP. While we are getting several new random number generators RNGs for simplicity Ill talk about the new RandomEngineSecure class . engine new RandomEngineSecure randomString enginegenerate a random binary string echo binhexrandomString Now if we want to do something like sort an array we need one of the new Randomizer objects. randomizer new RandomRandomizerengine items range randomizedItems randomizershuffleArrayitems print_rrandomizedItems In the example above we use the Secure engine.