Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Is there any reason to write public static function instead of just static function? It's still accessible via class name like Class::staticMethod() isn't?
Public is implicit (used if not declared otherwise), so it will work either way.
The point of writing public is to make your code cleaner, easier to read.
E.g. in java, the default visibility is not public, so when a java programmer reads your php, he'll wonder where the heck it is accessible from. Declaring it public saves some headache.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed last year.
Improve this question
Currently developing a Laravel app and a question came to mind.
Is any "technical" difference between this two ways to use a class?
First way:
public function store() {
new \Illuminate\Auth\Events\Registered($user)
}
VS
Second way:
use Illuminate\Auth\Events\Registered;
public function store() {
new Registered($user)
}
One way is more performant than the other?
Is any difference in the way PHP reads this lines?
When the class is only used once, is better to include it using first way or second way?
Also any other this than comes to mind...
No difference in performance but its personal choice but if you are using the class more than once in the same class importing once works well and looks clean in my view
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I read somewhere that defining constants with PHP's define function like so:
define('BASE_PATH','/var/www/html/example/');
is better and more secure than storing the same variable data inside a globals variable like so:
$_GLOBALS['BASE_PATH'] = '/var/www/html/example/';
Could somebody please explain the difference, which is better in which scenarios, and why?
I've just read here:
PHP Manual - The 'define' function
That the 'define' function can cause unwanted oddities.
a) What are the security implications of both?
b) How does PHP manage and store each of the variable's data in physical memory?
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
When it comes with Inheritance, what Exactly is the difference between method overriding and late static binding?
Late static binding is essentially method overriding for static methods. There are some subtle differences in how they are actually carried out by the compiler. See What exactly are late static bindings in PHP?
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
Basically I'm building a website that need a html like template called from the folder using their file name.
Should I use a enum/constant class or should I just call them straight to their filename?
Example:
abstract class ViewTemplate
{
const ORDER_HISTORY = 'order_history_template.html';
const PURCHASE_HISTORY = 'purchase_history_template.html';
//etc...
}
Is this kind of class necessary and do they hog a lot of resources if I call the class when I have a lot of template?
Since the filename is a unique identifier - unless you expect the file names to change in the future (which isn't likely, and even if it happens refactoring is simple) there is no point to it.
You already have a unique identifier for a file you're loading. The only benefit of passing an enumeration with properties here is type-safety but you're only calling it once anyway so a typo could happen in one place anyway.
So overall it's redundant.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I was wondering what are the pros and cons of these 2 programming styles, is it just a matter of taste or is one the desired way?
using a method return value as an argument for another method :
public function add($data)
{
$this->uploadFilesToPreflight(
$this->addOrderFilesToDB(
$data['shop'],
$data['filesData']
)
);
}
VS setting a protected class variable in method 1 and using it as method 2 argument:
public function add($data)
{
//does some stuff and sets $orderFilesArray
$this->addOrderFilesToDB($data['shop'], $data['filesData']);
$this->uploadFilesToPreflight($this->orderFilesArray);
}
The question is, what is the class supposed to be? And does the class have a state?
If the class is supposed to be a service where add($data) can be called multiply times and the behavior should not change the first option would be better.
If the class has a state and it's behavior is supposed to change by call add($data) then the second option is fine but you have to be aware that this can cause side-effects if the class has other methods that rely on $this->orderFilesArray.
To provide a better answer on what option is best, you would have to post a broader context of the class.