photog.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
A place for your photos and banter. Photog first is our motto Please refer to the site rules before posting.

Administered by:

Server stats:

252
active users

#phptip

0 posts0 participants0 posts today
dseguy<p>http_build_query() is able to convert enum cases directly into URL query variables in <a href="https://phpc.social/tags/PHP" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>PHP</span></a> 8.4. </p><p>This is an example of agile usage of backed enumeration. An inspiration for the future, that will promote enumeration further? </p><p><a href="https://phpc.social/tags/phptip" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>phptip</span></a> <a href="https://phpc.social/tags/phptrick" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>phptrick</span></a> </p><p><a href="https://php-tips.readthedocs.io/en/latest/tips/http_build_query_enum.html" rel="nofollow noopener noreferrer" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">php-tips.readthedocs.io/en/lat</span><span class="invisible">est/tips/http_build_query_enum.html</span></a></p>
dseguy<p>'namespace' is both a keyword to introduce a namespace, and to represent the current namespace in a name. </p><p>This means it must be used with caution, before calling 'namespace\namespace'. </p><p><a href="https://phpc.social/tags/phptip" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>phptip</span></a> <a href="https://phpc.social/tags/phptrick" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>phptrick</span></a></p><p><a href="https://php-tips.readthedocs.io/en/latest/tips/namespace_but_far.html" rel="nofollow noopener noreferrer" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">php-tips.readthedocs.io/en/lat</span><span class="invisible">est/tips/namespace_but_far.html</span></a></p>
dseguy<p>A hidden nullable, is using a NULL as a default for a typed parameter: it makes it implicitely nullable. This is deprecated in <a href="https://phpc.social/tags/PHP" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>PHP</span></a> 8.4</p><p>A hidden non-nullable, is when the null is in a constant: the parameter then stays non-nullable.</p><p><a href="https://phpc.social/tags/phptip" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>phptip</span></a> <a href="https://phpc.social/tags/phptrick" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>phptrick</span></a></p><p><a href="https://php-tips.readthedocs.io/en/latest/tips/no-hidden-nullable.html" rel="nofollow noopener noreferrer" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">php-tips.readthedocs.io/en/lat</span><span class="invisible">est/tips/no-hidden-nullable.html</span></a></p>
dseguy<p><a href="https://phpc.social/tags/PHP" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>PHP</span></a> final keyword does not apply to parameters. </p><p>This means that a final property cannot be a promoted property: both declarations are mutually exclusive. </p><p><a href="https://phpc.social/tags/phptip" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>phptip</span></a> <a href="https://phpc.social/tags/phptrick" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>phptrick</span></a></p><p><a href="https://php-tips.readthedocs.io/en/latest/tips/no-final-parameter.html" rel="nofollow noopener noreferrer" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">php-tips.readthedocs.io/en/lat</span><span class="invisible">est/tips/no-final-parameter.html</span></a></p>
dseguy<p>There is a <a href="https://phpc.social/tags/PHP" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>PHP</span></a> value, which is not even equal to itself. <br>($a === $a) is false! </p><p>If you don't know about it, here is a tip : it is not a number.</p><p><a href="https://phpc.social/tags/phptip" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>phptip</span></a> <a href="https://phpc.social/tags/phptrick" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>phptrick</span></a></p><p><a href="https://php-tips.readthedocs.io/en/latest/tips/is_not_a_nan.html" rel="nofollow noopener noreferrer" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">php-tips.readthedocs.io/en/lat</span><span class="invisible">est/tips/is_not_a_nan.html</span></a></p>
dseguy<p><a href="https://phpc.social/tags/PHP" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>PHP</span></a> 8.4 added chaining new without parenthesis: accessing a property or a method, directly at instantiation time.</p><p>Which means, the object can also be invoked immediately! </p><p>new $x()();</p><p>Next, 3 sets of parenthesis! </p><p><a href="https://phpc.social/tags/phptip" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>phptip</span></a> <a href="https://phpc.social/tags/phptrick" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>phptrick</span></a> </p><p><a href="https://php-tips.readthedocs.io/en/latest/tips/invoke_on_new.html" rel="nofollow noopener noreferrer" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">php-tips.readthedocs.io/en/lat</span><span class="invisible">est/tips/invoke_on_new.html</span></a></p>
dseguy<p><a href="https://phpc.social/tags/PHP" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>PHP</span></a> 8.4 is deprecating the usage of _ (underscore) as a class name. Anyone knows why? </p><p>The same name is available for functions, methods and constants, so, with named parameters, we can still write the beauty below. </p><p><a href="https://phpc.social/tags/phptip" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>phptip</span></a> <a href="https://phpc.social/tags/phptrick" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>phptrick</span></a></p><p><a href="https://php-tips.readthedocs.io/en/latest/tips/no_more_class__.html" rel="nofollow noopener noreferrer" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">php-tips.readthedocs.io/en/lat</span><span class="invisible">est/tips/no_more_class__.html</span></a></p>
dseguy<p>"Cannot call constructor" is a real <a href="https://phpc.social/tags/PHP" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>PHP</span></a> error message. And there is also "Must call the parent constructor". </p><p>To call or not to call the constructor: definitely a question, and may be, an improvement for <a href="https://phpc.social/tags/PHP" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>PHP</span></a> 8.5. </p><p><a href="https://phpc.social/tags/phptip" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>phptip</span></a> <a href="https://phpc.social/tags/phptrick" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>phptrick</span></a></p><p><a href="https://www.exakat.io/en/php-constructors-and-inheritance/" rel="nofollow noopener noreferrer" translate="no" target="_blank"><span class="invisible">https://www.</span><span class="ellipsis">exakat.io/en/php-constructors-</span><span class="invisible">and-inheritance/</span></a></p>
dseguy<p>So, <a href="https://phpc.social/tags/PHP" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>PHP</span></a> has fluent interfaces, but it also can do fluent functions: functions that can be chain called. </p><p>As usual, it works but it is a tad cumbersome. </p><p><a href="https://phpc.social/tags/phptip" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>phptip</span></a> <a href="https://phpc.social/tags/phptrick" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>phptrick</span></a> </p><p><a href="https://php-tips.readthedocs.io/en/latest/tips/fluent_function.html" rel="nofollow noopener noreferrer" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">php-tips.readthedocs.io/en/lat</span><span class="invisible">est/tips/fluent_function.html</span></a></p>
dseguy<p>So, when there is an anonymous class that gave an anonymous <a href="https://phpc.social/tags/PHP" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>PHP</span></a> object, could you deanonymize it and use it somewhere else in the code? </p><p>Thanks to class_alias() and $object::class, it is possible! </p><p><a href="https://php-tips.readthedocs.io/en/latest/tips/deanonymize-class.html" rel="nofollow noopener noreferrer" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">php-tips.readthedocs.io/en/lat</span><span class="invisible">est/tips/deanonymize-class.html</span></a></p><p><a href="https://phpc.social/tags/phptip" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>phptip</span></a> <a href="https://phpc.social/tags/phptrick" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>phptrick</span></a></p>
dseguy<p>1) it is possible to call a method 'as', because relaxed keywords <a href="https://phpc.social/tags/PHP" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>PHP</span></a> methods</p><p>2) it is possible to import a method from a trait, and alias it to itself.</p><p>It is possible to write 'as as as ' in <a href="https://phpc.social/tags/PHP" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>PHP</span></a> and make sense.</p><p><a href="https://phpc.social/tags/phptip" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>phptip</span></a> <a href="https://phpc.social/tags/phptrick" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>phptrick</span></a> </p><p><a href="https://php-tips.readthedocs.io/en/latest/tips/as-as-as.html" rel="nofollow noopener noreferrer" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">php-tips.readthedocs.io/en/lat</span><span class="invisible">est/tips/as-as-as.html</span></a></p>
dseguy<p><a href="https://phpc.social/tags/PHP" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>PHP</span></a> 8.2 has the #[SensitiveParameter] attribute that hides values in debug messages. </p><p>There is also the SensitiveParameterValue class, that does the same, while working from the caller perspective. Get the value with $object-&gt;getValue()</p><p><a href="https://3v4l.org/KrViH" rel="nofollow noopener noreferrer" translate="no" target="_blank"><span class="invisible">https://</span><span class="">3v4l.org/KrViH</span><span class="invisible"></span></a></p><p><a href="https://phpc.social/tags/phptip" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>phptip</span></a> <a href="https://phpc.social/tags/phptrick" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>phptrick</span></a></p>