getter

Symfony ManyToOne relationship getter returns empty object

余生长醉 提交于 2019-12-05 09:57:55
I'll simplifly my code, I have te next: Doctor entity: use ...\...\Entity\Paciente; class Doctor extends Usuario { public function __construct() { ... $this->pacientes = new ArrayCollection(); ... } /** * Número de colegiado - numColegiado * * @var string * * @ORM\Column(name="numColegiado", type="string", length=255, unique=true) */ protected $numColegiado; /** * @ORM\OneToMany(targetEntity="Paciente", mappedBy="doctor") * @var \Doctrine\Common\Collections\ArrayCollection */ private $pacientes; ... } Paciente entity: use \...\...\Entity\Doctor; ... class Paciente extends Usuario { } /** *

Symfony call get by Name from variable

 ̄綄美尐妖づ 提交于 2019-12-05 08:40:33
I would like to call a getter with the stored fieldname from the database. For example, there are some fieldnames store like ['id','email','name']. $array=Array('id','email','name'); Normally, I will call ->getId() or ->getEmail().... In this case, I have no chance to handle things like this. Is there any possibility to get the variable as part of the get Command like... foreach ($array as $item){ $value[]=$repository->get$item(); } Can I use the magic Method in someway? this is a bit confusing.... You can do it like this : // For example, to get getId() $reflectionMethod = new

How often do you see abuse of C# shorthand getters/setters?

做~自己de王妃 提交于 2019-12-05 05:31:15
In C# you can create getter/setters in a simpler way than other languages: public int FooBar { get; set; } This creates an internal private variable which you can't address directly, with the external property 'FooBar' to access it directly. My question is - how often do you see this abused? It seems like it has a high potential to violate encapsulation best-practices often. Don't get me wrong, I use it as appropriate, and partial variations of it for read-only write-only types of properties, but what are your unpleasant experiences with it from other authors in your code base? Clarification:

Templates for setters and getters

假如想象 提交于 2019-12-05 03:34:37
I am not familiar with templates, but I wonder, if it is possible to use them for setter and getter methods. For example in this situation: double exmlClass::getA(void) const { return a_; } void exmlClass::setA(const double& a) { a_ = a; } double exmlClass::getB(void) const { return b_; } As you can see, methods are almost the same, except they refer to another private variables (a_, b_, c_). Is there a more elegant way to write those functions or it is common practice to do like above in such situations? And if its common to use templates, I would appreciate example how you would use them in

Why is a simple get-statement so slow?

亡梦爱人 提交于 2019-12-05 02:19:54
A few years back, I got an assignment at school, where I had to parallelize a Raytracer. It was an easy assignment, and I really enjoyed working on it. Today, I felt like profiling the raytracer, to see if I could get it to run any faster (without completely overhauling the code). During the profiling, I noticed something interesting: // Sphere.Intersect public bool Intersect(Ray ray, Intersection hit) { double a = ray.Dir.x * ray.Dir.x + ray.Dir.y * ray.Dir.y + ray.Dir.z * ray.Dir.z; double b = 2 * (ray.Dir.x * (ray.Pos.x - Center.x) + ray.Dir.y * (ray.Pos.y - Center.y) + ray.Dir.z * (ray.Pos

Java use getter in for loop or create a local variable? [duplicate]

自闭症网瘾萝莉.ら 提交于 2019-12-05 00:49:00
This question already has an answer here: java how expensive is a method call 12 answers I have a for loop which runs 4096 times and it should be as fast as possible. Performance is really important here. Currently I use getter methods inside the loop which just return values or objects from fields which don't change while the loop is in progress. Example: for (;;) { doSomething(example.getValue()); } Is there any overhead using getters? Is it faster using the following way? Example: Object object = example.getValue(); for (;;) { doSomething(object); } If yes, is that also true for accessing

Get and set (private) property in PHP as in C# without using getter setter magic method overloading

限于喜欢 提交于 2019-12-04 23:53:53
问题 Summary Code sample: Class People { // private property. private $name; // other methods not shown for simplicity. } Straight forward. Let me assume that $name is a PRIVATE class member (or property, variable, field, call it as you wish) . Is there any way to do these in PHP: $someone = new People(); $someone->name = $value; $somevar = $someone->name; WITHOUT using __get($name) and __set($name, $value) . Background I needed to check the assigned $value , therefore I simply need a getter

PHP: empty doesn't work with a getter method

夙愿已清 提交于 2019-12-04 23:46:49
I have a "getter" method like function getStuff($stuff){ return 'something'; } if I check it with empty($this->stuff) , I always get FALSE , but I know $this->stuff returns data, because it works with echo. and if I check it with !isset($this->stuff) I get the correct value and the condition is never executed... here's the test code: class FooBase{ public function __get($name){ $getter = 'get'.ucfirst($name); if(method_exists($this, $getter)) return $this->$getter(); throw new Exception("Property {$getter} is not defined."); } } class Foo extends FooBase{ private $my_stuff; public function

Best practice since JavaFX setters/getters are final?

六眼飞鱼酱① 提交于 2019-12-04 22:02:13
In the process of converting a Windows application from Swing to JavaFX. We had a lot of custom components that previously overrode the mutator methods of JTextField, for example. In JavaFX these methods are declared final. Should I just be creating wrapper methods that call the final methods and modify the values before and after? I just want to make sure I go about doing it the right way from the beginning. Edit: I will also include the fact that some of this code is from much older versions of Java. So it's possible certain things are no longer necessary. This is an example of a setText

How to pull a field from an object stored in an arraylist?

做~自己de王妃 提交于 2019-12-04 18:41:44
Can I get some working code examples that I can pick apart and study how they work? Specifically, I need to figure out how do I get the address field from the x numbered object in my list? How do I delete the xth object from the list? How do I set the price field of object x to a new value? I understand how the houseList.add places the data into a new object that is appended to the end of the list, but I do not understand the converse of it and how to target a specific object and manipulate it. Please show a working multi-class example. Thanks! The class that creates the House object and it