Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87565 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 9659 invoked from network); 3 Aug 2015 09:39:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Aug 2015 09:39:10 -0000 Authentication-Results: pb1.pair.com header.from=nicolai.scheer@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nicolai.scheer@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.160.173 as permitted sender) X-PHP-List-Original-Sender: nicolai.scheer@gmail.com X-Host-Fingerprint: 209.85.160.173 mail-yk0-f173.google.com Received: from [209.85.160.173] ([209.85.160.173:36324] helo=mail-yk0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1A/C3-22506-DB63FB55 for ; Mon, 03 Aug 2015 05:39:09 -0400 Received: by ykeo23 with SMTP id o23so8862247yke.3 for ; Mon, 03 Aug 2015 02:39:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=2IPx/gug8IC4lfTB6uMURRMmCgjMUfbv5fiuRakZqJ4=; b=MrDfw4ViYBVAqrNBS5YZ8rmF8JwuL7LvEwrBsVkH+nXm+nI/MN60bCUpgH1oh1hsCp AuRHSmYzVNTGCpiQqxMOEYPIJ+fd+tRXFyOzX1zRGKjBr24wbltXQmkX4EKfnuM1HeB6 isA+Fgm1DQkGUmyXfbXTxDuXEFa4djKvU18Gs/F5Dhh227WfDR4HWh4IqkE0Gb8k8/Jn aJXdGoC4NVcMxWzuR2hl9TUOTVT3yNG+9ZoBSLewpdLGBjreatA0NZ8xRzO1JbMNhcNs L3lusGM+Z6ZjdccbBWNFrNAS7pOkE+NKCT93PX4w+rnAnwgpQ6R0bPmHC7CbwVgbmGmD 7K7g== MIME-Version: 1.0 X-Received: by 10.129.117.196 with SMTP id q187mr19282242ywc.15.1438594745888; Mon, 03 Aug 2015 02:39:05 -0700 (PDT) Received: by 10.37.52.197 with HTTP; Mon, 3 Aug 2015 02:39:05 -0700 (PDT) Date: Mon, 3 Aug 2015 11:39:05 +0200 Message-ID: To: PHP Internals Content-Type: text/plain; charset=UTF-8 Subject: Access of protected members From: nicolai.scheer@gmail.com (Nicolai Scheer) Hi, just stumbled upon a strange issue. I always thought that protected/private member variables can only be altered from inside the object. This example shows, that this is not true: class Test { protected $member = null; public static function getObj() { $myself = new Test(); $myself->member = "hello world"; return $myself; } } $new_object = Test::getObj(); var_dump( $new_object ); The output is: object(Test)#1 (1) { ["member":protected]=> string(11) "hello world" } Of course, I'm "inside" the right class, nevertheless, the object stored in $myself should not allow direct access to its members. Is this the expected behaviour? Code of this kind is used quite frequently for factory methods. Greetings Nico