private

PHP5 member visibility

纵饮孤独 提交于 2019-12-12 01:42:39
问题 Could someone explain me, why is it possible to do the following in PHP, but, for example, not in C# or Java: Class A { protected $a = 'Howdy!'; } Class B extends A { public function howdy() { $created = new A(); echo $created->a; <----- This is legal due to per-class visibility } } $b = new B(); echo $b->howdy(); <----- Hence, no fatal error here This behavior seems to be specified here, but I can't understand the fundamental reason behind this (to my mind, one can't simply implement the per

BlockChain: Private block chain technologies [closed]

眉间皱痕 提交于 2019-12-11 14:40:03
问题 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 last year . As far as i understand, private block chains are built for an enterprise or a group of organizations. While i am trying to explore, i came across few technologies like Hyperledger fabric, OpenChain, multiChain. What are the technologies using which a private Block Chain can be built

Implementing instance members/methods in JavaScript

时间秒杀一切 提交于 2019-12-11 13:59:39
问题 This question stems from a problem I was trying to solve regarding the ability to have "private" instance variables in JavaScript. You may want to read this, prior to my question. For the sake of completeness, I have illustrated my entire problem, before asking the question. My hope is that this will provide a complete example of how to implement instance members and methods correctly in JavaScript, and for any developer who lands here, to understand the pitfalls of the various

How come the PHP private class var is not private?

故事扮演 提交于 2019-12-11 13:51:54
问题 I was programming, and came across this problem: In the code sample below, a public function sets a private varriable. Now one would expect the content of that private varriable is private, thought the $GLOBALS varriable (a superglobal) can access it, and at least read it. why? is there a way to prefent this? <?PHP error_reporting( E_ALL ); class test { private $test = ''; public function test() { $this->test = 'Can u see me?'; } } $b = new test(); $b->test(); pre( $GLOBALS['b'] ); // Result:

static and private method behavior when calling direct on object of child class sounds like overriding?

回眸只為那壹抹淺笑 提交于 2019-12-11 12:34:06
问题 public class B extends A{ public static void main(String[] args) { new B().privateMethod();//no error -output B-privateMethod.Sounds like overriding new B().staticMethod(); //no error -output B-StaticMethod.Sounds like overriding } private void privateMethod() { System.out.println("B-privateMethod."); } static void staticMethod() { System.out.println("B-StaticMethod."); } } class A{ private void privateMethod() { System.out.println("A-privateMethod."); } static void staticMethod() { System

Copy javascript object with private member

北城余情 提交于 2019-12-11 12:25:17
问题 I've looked all around and found nothing to help me. Why on earth can't I clone a javascript object with private members without making them quantum entangled? Just look at this code... It's a plain private property with getter and setter. Somehow if I call the public setter on one instance, the cloned one gets changed too. Why? Can it be worked around? obj = function(){ var changed = 0; this.getChanged = function(){ return changed; } this.setChanged = function(){ changed = 1; } this

Is there a way to protect a class variable from being modified outside of a function

守給你的承諾、 提交于 2019-12-11 10:41:12
问题 I have a volume variable that I want to be protected from modification unless the person calls a certain function. Is there a way to make it to where it can only be modified by that function other than creating a private class within the class. I suppose that creating a private class is a good idea, but I would be interested if someone else has a different approach. AudioPlayer should never be allowed to change the volume without calling SetVolume. That's the code I have here, but I wondered

Why are private methods not working with polymorphism?

一曲冷凌霜 提交于 2019-12-11 10:10:13
问题 Kind of got a problem using inheritance/polymorphism with private methods. Example: class cmsPage{ private function getBlock(){ $block = new cmsBlock(); return $block } function createBlock(){ $block = $this->getBlock(); $block->save(); } //... do various things } class specialCmsPage extends cmsPage{ private function getBlock(){ $block = new specialCmsBlock(); return $block } } Naturally I want specialCmsPage to inherit all the methods from cmsPage. The Function getBlock() should make sure

How to cast to a private inner class when type information is unavailable?

谁都会走 提交于 2019-12-11 08:47:58
问题 I have a situation similar to the following: // In some library code public class A { private class B { Object value; } } // In my code Object o; // o is initialized to an instance of B somehow // ... B bInstance = (B) o; How would I go about casting an Object to type B given that the type of B is inaccessible ? To explain in more detail, A is not part of my code base. It's part of a library. I have access to an object that I know is of type B, but I can't cast it (in an IDE, for example)

C++ access specifiers

末鹿安然 提交于 2019-12-11 08:37:01
问题 I just want to make sure I got the idea of public and private right. Regarding the private access specifier, does it mean: Only accessed inside the class Cannot be accessed from the object of the class unless there are public class methods that can be used to access them ( Can other objects use those public functions? ) No other object can access them And for public: Accessed from the object of the class Accessed from any other object Is that right? 回答1: I think there is an issue of