Hi all,
I'm emailling to ask why __call isn't called when you call a private
method from outside of function...
In my opinion, this error should exist, but when you haven't an __call
function, because outside the scope of class it only should see public
methods, then if it don't exist it should call the __call
Fatal error: Call to private method user::print_user() from context
'' in /home/diogo/Documents/devspace/mangas.dev/index.php on line 47
Of course my opinion only counts what it counts, not too much I believe :)
Anyway, it's the correct beaviour or its bugie?
Make my opinion some sense?
Is there anyway of implement or own magic method that gets called
before any method in a given class?
--
Thanks by your attention,
Diogo Neves
Web Developer @ SAPO.pt by PrimeIT.pt
Diogo Neves escribió:
Hi all,
I'm emailling to ask why __call isn't called when you call a private
method from outside of function...
Please provide example code ;-)
--
"A computer is like an Old Testament god, with a lot of rules and no
mercy. "
Cristian Rodríguez R.
Platform/OpenSUSE - Core Services
SUSE LINUX Products GmbH
Research & Development
http://www.opensuse.org/
Cristian Rodríguez wrote:
Diogo Neves escribió:
Hi all,
I'm emailling to ask why __call isn't called when you call a private
method from outside of function...Please provide example code ;-)
He means this:
class foo {
private function bar() { }
function __call($f,$a) {
echo "called $f";
}
}
$a = new foo;
$a->bar();
Exactly...
Is that normal workings or more like a bugie one?
Cristian Rodríguez wrote:
Diogo Neves escribió:
Hi all,
I'm emailling to ask why __call isn't called when you call a private
method from outside of function...Please provide example code ;-)
He means this:
class foo {
private function bar() { }
function __call($f,$a) {
echo "called $f";
}
}
$a = new foo;
$a->bar();
--
Thanks by your attention,
Diogo Neves
Web Developer @ SAPO.pt by PrimeIT.pt
Exactly...
Is that normal workings or more like a bugie one?
Definitely not a bug.
I believe the reason is that if you enable __call() in this case,
you'd have different behavior depending on the calling scope,
i.e. complete mess.
Also there would be no way to know you're calling a method you're
not supposed to call (unless you trigger an error yourself).
--
Wbr,
Antony Dovgal
Hi again,
Exactly...
Is that normal workings or more like a bugie one?
Definitely not a bug.
Ok, it's implemented to work like that... less bad ;)
I believe the reason is that if you enable __call() in this case, you'd have
different behavior depending on the calling scope, i.e. complete mess.
Well, if things don't behave diferent depending on scope then why
private exists anyway?
And the scope is being controlled already, that's why i get an fatal
error, right?
If the method is private, why it simple don't "think" it doesn't exist
when outside of class scope?
Maybe it don't make sense but...
class foo {
private function bar() { }
function __call($f,$a) {
echo "called $f";
}
}
$a = new foo;
// There ( ouside the class scope ) ...
// ... this exist as much ...
$a->bar();
// ... as this, right?
$a->bar1();
Even if it looks like a mess... it makes some sense, no?
Unless u say me that a class isn't a scope because I never understood
the php scopes, maybe u can recomend me a good article about it or
some link somewhere
Also there would be no way to know you're calling a method you're not
supposed to call (unless you trigger an error yourself).--
Wbr, Antony Dovgal
--
Thanks by your attention,
Diogo Neves
Web Developer @ SAPO.pt by PrimeIT.pt
Antony,
I don't at all disagree about the inappropriateness of this not triggering
an error but I did want to point out that this behavior is not consistent
with how __get() works. It seems like they should all behave similarly when
dealing with overriding methods or properties of different access levels.
+++ Attempting to access a private property
mikel@mikel-desktop:~$ php -r 'class A { private $a; } $a = new A; $a->a;'
Fatal error: Cannot access private property A::$a in Command line code on
line 1
+++ Attempting to access a private property when __get() is defined
mikel@mikel-desktop:~$ php -r 'class A { private $a; public function
__get($var) { echo $var, "\n"; } } $a = new A; $a->a;'
a
+++ Attempting to access a private method
mikel@mikel-desktop:~$ php -r 'class A { private function a() {} } $a = new
A; $a->a();'
Fatal error: Call to private A::a() from invalid context in Command line
code on line 1
++ Attempting to access a private method when __call is defined
mikel@mikel-desktop:~$ php -r 'class A { private function a() {} public
function __call($method, $parms) { echo $method, "\n"; } } $a = new A;
$a->a();'
Fatal error: Call to private A::a() from invalid context in Command line
code on line 1
Exactly...
Is that normal workings or more like a bugie one?
Definitely not a bug.
I believe the reason is that if you enable __call() in this case, you'd
have different behavior depending on the calling scope, i.e. complete mess.
Also there would be no way to know you're calling a method you're not
supposed to call (unless you trigger an error yourself).--
Wbr, Antony Dovgal
Hi,
__get() makes more sense to me, and maybe was where | got the ideia
because | never used __call() before but i add used __get() :(
Maybe the php folks change its behavior in future...
It's worthy of a bug report ( I ask because i'm not very involved in
php community )
Thanks,
Antony,
I don't at all disagree about the inappropriateness of this not triggering
an error but I did want to point out that this behavior is not consistent
with how __get() works. It seems like they should all behave similarly when
dealing with overriding methods or properties of different access levels.+++ Attempting to access a private property
mikel@mikel-desktop:~$ php -r 'class A { private $a; } $a = new A; $a->a;'
Fatal error: Cannot access private property A::$a in Command line code on
line 1+++ Attempting to access a private property when __get() is defined
mikel@mikel-desktop:~$ php -r 'class A { private $a; public function
__get($var) { echo $var, "\n"; } } $a = new A; $a->a;'
a+++ Attempting to access a private method
mikel@mikel-desktop:~$ php -r 'class A { private function a() {} } $a = new
A; $a->a();'
Fatal error: Call to private A::a() from invalid context in Command line
code on line 1++ Attempting to access a private method when __call is defined
mikel@mikel-desktop:~$ php -r 'class A { private function a() {} public
function __call($method, $parms) { echo $method, "\n"; } } $a = new A;
$a->a();'Fatal error: Call to private A::a() from invalid context in Command line
code on line 1Exactly...
Is that normal workings or more like a bugie one?
Definitely not a bug.
I believe the reason is that if you enable __call() in this case, you'd
have different behavior depending on the calling scope, i.e. complete mess.
Also there would be no way to know you're calling a method you're not
supposed to call (unless you trigger an error yourself).--
Wbr, Antony Dovgal--
--
Thanks for your attention,
Diogo Neves
Web Developer @ SAPO.pt by PrimeIT.pt
Hi again,
I'm workarrounding ( I really don't know if that word exists ) with an
'_' on private methods, but u can that that off on user class to see
this error:
Fatal error: Call to private method user::print_user() from context
'' in /home/diogo/Documents/devspace/mangas.dev/index.php on line 47
PS: This is test code, it's a mess and it's bad naming and coding
standards, don't that that part too serious.
Diogo Neves escribió:
Hi all,
I'm emailling to ask why __call isn't called when you call a private
method from outside of function...Please provide example code ;-)
--
"A computer is like an Old Testament god, with a lot of rules and no
mercy. "Cristian Rodríguez R.
Platform/OpenSUSE - Core Services
SUSE LINUX Products GmbH
Research & Development
http://www.opensuse.org/
--
Thanks by your attention,
Diogo Neves
Web Developer @ SAPO.pt by PrimeIT.pt