php-general Digest 15 Mar 2012 10:43:23 -0000 Issue 7728
Topics (messages 317014 through 317015):
Re: Randomly unable to read set variable from class
317014 by: Adrian Basalic
class method visibility
317015 by: Jeremy Wei
Administrivia:
To subscribe to the digest, e-mail:
[email protected]
To unsubscribe from the digest, e-mail:
[email protected]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
Loaded modules:
core prefork http_core mod_so mod_auth_basic mod_auth_digest mod_authn_file
mod_authn_alias mod_authn_anon mod_authn_dbm mod_authn_default
mod_authz_host mod_authz_user mod_authz_owner mod_authz_groupfile
mod_authz_dbm mod_authz_default util_ldap mod_authnz_ldap mod_include
mod_log_config mod_logio mod_env mod_ext_filter mod_mime_magic mod_expires
mod_deflate mod_headers mod_usertrack mod_setenvif mod_mime mod_dav
mod_status mod_autoindex mod_info mod_dav_fs mod_vhost_alias mod_negotiation
mod_dir mod_actions mod_speling mod_userdir mod_alias mod_substitute
mod_rewrite mod_proxy mod_proxy_balancer mod_proxy_ftp mod_proxy_http
mod_proxy_ajp mod_proxy_connect mod_cache mod_suexec mod_disk_cache mod_cgi
mod_version mod_fcgid mod_perl mod_php5 mod_python mod_ssl
-----Original Message-----
From: Camilo Sperberg [mailto:[email protected]] On Behalf Of Camilo
Sperberg
Sent: Wednesday, March 14, 2012 1:42 AM
To: Adrian Basalic
Cc: [email protected]
Subject: Re: [PHP] Randomly unable to read set variable from class
Sorry wasn't able to reproduce it on my test machine.
Do you have any external modules loaded such as APC, memcached, xDebug maybe
or other that can affect the output on that machine?
Greetings
On 13 Mar 2012, at 17:02, Adrian Basalic wrote:
> I have an issue that occurs randomly on a machine. After a number of
reloads
> of the page i can't read $this->_foo although it is set (var_dump shows it
> but the script cannot read it). The code works locally and on other
machines
> i tested. Apache restart seems to fix it but only temporary.
>
> Environment:
>
> . PHP Version 5.3.3
>
> . Linux 2.6.32-220.2.1.el6.x86_64 #1 SMP Fri Dec 23 02:21:33 CST
> 2011 x86_64
>
> . Apache 2.0
>
>
>
> class FooBar
>
> {
>
> protected $_foo;
>
> public function setFoo($bar)
>
> {
>
> if (!$bar) {
>
> print_r("Cannot find bar");
>
> }
>
> $this->_foo = $bar;
>
> if (!$this->_foo) {
>
> print_r("Cannot read {$this->_foo} set with $bar");
>
> var_dump($this);
>
> }
>
> var_dump($this);
>
> return $this;
>
> }
>
> }
>
>
>
> $foobar = new FooBar;
>
> $foobar->setFoo('bar');
>
>
>
> The output when this happens would be:
>
>
>
> Cannot read set with barobject(FooBar)#1 (1) { ["_foo":protected]=>
> string(3) "bar" } object(FooBar)#1 (1) { ["_foo":protected]=> string(3)
> "bar" }
>
>
>
> I'm going nuts here, and nobody seems to be able to reproduce this. Where
> should I start looking?
>
_______________________
Mi blog
CHW
Mi Twitter
--- End Message ---
--- Begin Message ---
I read the manual about method visibility, but i can't understand the
code below:
<?php
class Bar
{
public function test() {
$this->testPrivate();
$this->testPublic();
}
public function testPublic() {
echo "Bar::testPublic\n";
}
private function testPrivate() {
echo "Bar::testPrivate\n";
}
}
class Foo extends Bar
{
public function testPublic() {
echo "Foo::testPublic\n";
}
private function testPrivate() {
echo "Foo::testPrivate\n";
}
}
$myFoo = new foo();
$myFoo->test(); // Bar::testPrivate
// Foo::testPublic
?>
in class Bar's method test, why "$this->testPrivate();" invoked
testPrivate method of class Bar,
but not the testPrivate of class Foo? here $this shoud be the
reference of the instance of class Foo,
isn't it?
--
JeremyWei(魏志锋,字静之)
Mob: 18914495716
新浪微博:@JeremyWei
QQ: 327493482
Home: www.weizhifeng.net
Less is more
--- End Message ---