I have the following two codes:
<?php
class pagamentos {
public $tipo = array('avista', 'aprazo', 'outros');
function fPag($type) {
return in_array($type, $this->tipo);
}
}
This way I would use this as follows:
<?php
$cPagamentos = new pagamentos();
if ($cPagamentos->fPag('avista')) {
// É uma forma válida
}
My classmate did the same procedure, but in a different way:
<?php
class pagamentos {
public static $tipo = array('avista', 'aprazo', 'outros');
function fPag($type) {
return in_array($type, self::tipo);
}
}
Used differently:
<?php
if ($cPagamentos::fPag('avista')) {
// É uma forma válida
}
What I realized was that in his case, he did not need to instantiate the object.
- Is there a difference in memory allocation between these two forms of use?
- What is the theoretical difference between
self
and$this
in these 2 functions?
I've researched, but I ended up getting confused more and I did not understand the concept.