Reply to thread

As of XF 2.2.7 we have a command which generates use function lines automatically with the functions listed being enumerated from usage in the class itself and within the whitelist of native functions where this should be of benefit.


[CODE="php"]

<?php


namespace XF\Entity;


use XF\Mvc\Entity\Entity;

use XF\Mvc\Entity\Structure;


use function count, is_array, is_int;

[/CODE]


The command is: xf-dev:class-use-function <addon>, e.g. xf-dev:class-use-function XFMG though if you're running this on your own add-ons proceed with caution if you already use use function statements at all.


For example, we don't mess with existing use function lines which contain aliases, e.g.

[CODE]use function in_array, preg_match AS pm;

[/CODE]

So a new use function line gets added and therefore this may get turned into:

[CODE]use function in_array, preg_match AS pm;

use function in_array;

[/CODE]

Which is a fatal error.


On the whole, we're not necessarily expecting people to use this on their own add-ons, nor necessarily supporting that unless there are some obvious bugs to fix or improvements we can make and I suspect most people probably just inline them with the backslash prefix anyway.


Back
Top Bottom