Code Completion for private/protected member variables when using magic __get()

Asked
Active3 hr before
Viewed126 times

8 Answers

variablescompletion
90%

Note that there is no correlation between the actual code and the annotation. Zend Studio will show whatever you set for @property, regardless of this property existing. It will also not check if there actually is a magic method available.,Code Completion for Magic Methods can be achieved by using the @property and @method annotation in the DocBlock of the class (not in the Method Docs).,How do I setup code completion to work on Zend Studio (or any Eclipse based IDE) when working with a class that has private or protected member variables WITHOUT resorting to a bunch of Getter's OR setting the member vars as public., Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers

Code Completion for Magic Methods can be achieved by using the @property and @method annotation in the DocBlock of the class (not in the Method Docs).

/**
 * @property string bark
 */
class Dog {
   /* ... */
}

$Dog = new Dog();
echo $Dog - > // will autocomplete now
88%

How do I setup code completion to work on Zend Studio (or any Eclipse based IDE) when working with a class that has private or protected member variables WITHOUT resorting to a bunch of Getter's OR setting the member vars as public.,Code Completion for Magic Methods can be achieved by using the @property and @method annotation in the DocBlock of the class (not in the Method Docs).,Note that there is no correlation between the actual code and the annotation. Zend Studio will show whatever you set for @property, regardless of this property existing. It will also not check if there actually is a magic method available.

For example:

class Dog {

   protected $bark = 'woof!';

   public
   function __get($key) {
      if (isset($this - > $key)) {
         return $this - > $key;
      }
   }

}

$Dog = new Dog();
echo $Dog - > bark; // <-- I want the IDE to "know" that bark is a property of Dog.
load more v
72%

How do I setup code completion to work on Zend Studio (or any Eclipse based IDE) when working with a class that has private or protected member variables WITHOUT resorting to a bunch of Getter's OR setting the member vars as public.,Code Completion for Magic Methods can be achieved by using the @property and @method annotation in the DocBlock of the class (not in the Method Docs).,If you just want to initialize a class with some defaults, there is a rich new syntax set for function argument and destructuring defaults you can use. To give a simple example:,Note that there is no correlation between the actual code and the annotation. Zend Studio will show whatever you set for @property, regardless of this property existing. It will also not check if there actually is a magic method available.

For example:

class Dog {

   protected $bark = 'woof!';

   public
   function __get($key) {
      if (isset($this - > $key)) {
         return $this - > $key;
      }
   }

}

$Dog = new Dog();
echo $Dog - > bark; // <-- I want the IDE to "know" that bark is a property of Dog.
load more v
65%

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas php eclipse zend-studio code-completion or haz tu propia pregunta. ,¿Cómo configuro la finalización del código para que funcione en Zend Studio (o cualquier IDE basado en Eclipse) cuando trabajo con una clase que tiene variables miembro privadas o protegidas SIN recurrir a un grupo de Getter's O configurando las vars miembro como públicas?, @Matthieu también debería funcionar con Eclipse. Pero no me metas en eso. - Gordon , Sí, funciona en Eclipse PDT. Sabía que esto era posible, pero lo estaba buscando por todas partes. La anotación @method en la clase es una solución increíble para métodos abstractos / heredados elegantes. - Dustin Graham

Por ejemplo:

class Dog {

   protected $bark = 'woof!';

   public
   function __get($key) {
      if (isset($this - > $key)) {
         return $this - > $key;
      }
   }

}

$Dog = new Dog();
echo $Dog - > bark; // <-- I want the IDE to "know" that bark is a property of Dog.
load more v
75%

Class methods may be defined as public, private, or protected. Methods declared without any explicit visibility keyword are defined as public. , As of PHP 7.1.0, class constants may be defined as public, private, or protected. Constants declared without any explicit visibility keyword are defined as public. , Class properties must be defined as public, private, or protected. If declared using var, the property will be defined as public. , The visibility of a property, a method or (as of PHP 7.1.0) a constant can be defined by prefixing the declaration with the keywords public, protected or private. Class members declared public can be accessed everywhere. Members declared protected can be accessed only within the class itself and by inheriting and parent classes. Members declared as private may only be accessed by the class that defines the member.

string(5)
"hello"
Accessed the private method.
40%

PHP Magic methods start with double underscores (__).,By convention, the names of magic methods start with a double underscore (__). And PHP reserves the methods whose names start with a double underscore (__) for magic methods.,When you attempt to access a property that doesn’t exist or a property that is in-accessible e.g., private or protected property, PHP automatically calls the __get() method.,PHP calls the __get() method automatically when you access a non-existing or inaccessible property.

When you attempt to write to a non-existing or inaccessible property, PHP calls the __set() method automatically. The following shows the syntax of the __set() method:

.wp - block - code {
      border: 0;
      padding: 0;
   }

   .wp - block - code > div {
      overflow: auto;
   }

   .shcb - language {
      border: 0;
      clip: rect(1 px, 1 px, 1 px, 1 px); -
      webkit - clip - path: inset(50 % );
      clip - path: inset(50 % );
      height: 1 px;
      margin: -1 px;
      overflow: hidden;
      padding: 0;
      position: absolute;
      width: 1 px;
      word - wrap: normal;
      word - break: normal;
   }

   .hljs {
      box - sizing: border - box;
   }

   .hljs.shcb - code - table {
      display: table;
      width: 100 % ;
   }

   .hljs.shcb - code - table > .shcb - loc {
      color: inherit;
      display: table - row;
      width: 100 % ;
   }

   .hljs.shcb - code - table.shcb - loc > span {
      display: table - cell;
   }

   .wp - block - code code.hljs: not(.shcb - wrap - lines) {
      white - space: pre;
   }

   .wp - block - code code.hljs.shcb - wrap - lines {
      white - space: pre - wrap;
   }

   .hljs.shcb - line - numbers {
      border - spacing: 0;
      counter - reset: line;
   }

   .hljs.shcb - line - numbers > .shcb - loc {
      counter - increment: line;
   }

   .hljs.shcb - line - numbers.shcb - loc > span {
      padding - left: 0.75 em;
   }

   .hljs.shcb - line - numbers.shcb - loc::before {
      border - right: 1 px solid #ddd;
      content: counter(line);
      display: table - cell;
      padding: 0 0.75 em;
      text - align: right; -
      webkit - user - select: none; -
      moz - user - select: none; -
      ms - user - select: none;
      user - select: none;
      white - space: nowrap;
      width: 1 % ;
   }
public __set(string $name, mixed $value): voidCode language: PHP(php)
load more v
22%

Private Variables in Python,Type Conversion in Python,Download and Install Python 3 Latest Version,Iterate over a list in Python

60%

Methods inside classes must always declare their visibility by using one of the private, protected, or public modifiers. ,6.2 Class member variables,The var construct is not permitted. Member variables always declare their visibility by using one of the private, protected, or public modifiers. Giving access to member variables directly by declaring them as public is permitted but discouraged in favor of accessor methods (set/get). ,6 Classes 6.1 Class declarations 6.2 Class member variables

< ? php

require('config.php');
load more v

Other "variables-completion" queries related to "Code Completion for private/protected member variables when using magic __get()"