class

PDO objects across classes

爷,独闯天下 提交于 2020-01-14 20:38:09
问题 I'm looking for some feedback on the following: I currently have two classes, which are being used in my PHP application. A database connection class, which is currently using MySQL (but switching to PDO ). Another class (with several functions) which requires database functionality. I'm looking for the best way to design this, I've read up on singletons (with very mixed reviews), read examples where objects were simply declared as new for each method (class functions), and examples where the

Pythonic Way To Check for A Parameter Type

拜拜、爱过 提交于 2020-01-14 19:25:51
问题 I'm working on a little side project for work and have made some classes and methods. One of the classes represents a shelf in our inventory and another represents each a bin on the shelf. I have a method to add a new bin to the shelf and I added some logic to make sure it was passed a Location object before it is added to the shelf (right now I'm using lists while I develop before moving everything to a DB). However I just read in a Python book that I have that it is usually better to handle

where is the fatal error “Cannot access empty property” in the PHP class function?

末鹿安然 提交于 2020-01-14 18:56:14
问题 What is wrong with this code? <?php class users { var $user_id, $f_name, $l_name, $db_host, $db_user, $db_name, $db_table; function users() { $this->$db_host = 'localhost'; $this->$db_user = 'root'; $this->$db_name = 'input_oop'; $this->$db_table = 'users'; } function userInput($f_name, $l_name) { $dbc = mysql_connect($this->db_host , $this->db_user, "") or die ("Cannot connect to database : " .mysql_error()); mysql_select_db($this->db_name) or die (mysql_error()); $query = "insert into $this

vue 点击动态切换样式

£可爱£侵袭症+ 提交于 2020-01-14 18:47:08
<template> <div> <el-row> <el-col :span="8" class="el-col" :class="{'BorderActive':isActive===1}" > <div > <img src="/img/map/basemap.png" @click="selectMap(1)"> <div class="zi-ti" :class="{'Zi-tiActive':isActive===1}">基础地形图</div> </div> </el-col> <el-col :span="8" class="el-col" :class="{'BorderActive':isActive===2}"> <div > <img src="/img/map/sallite.png" @click="selectMap(2)"> <div class="zi-ti" :class="{'Zi-tiActive':isActive===2}">基础影像底图</div> </div> </el-col> <el-col :span="8" class="el-col" :class="{'BorderActive':isActive===3}" > <div> <img src="/img/map/basemap.png" @click="selectMap

Placement new on non-pointer variables and class members

不羁岁月 提交于 2020-01-14 16:49:02
问题 Consider the following example: #include <iostream> struct A { int i; A(int i) { this->i = i; } A &operator=(const A &a) = delete; A(const A &a) = delete; }; int main() { A a(1); new(&a) A(5); //a = A(7); // not allowed since = is deleted in A std::cout << a.i << std::endl; } This is a simple example using the placement new operator. Since the copy constructor and assignment operator of struct A have been deleted (for whatever reason), it is not possible to change the object the variable A a

Placement new on non-pointer variables and class members

久未见 提交于 2020-01-14 16:46:31
问题 Consider the following example: #include <iostream> struct A { int i; A(int i) { this->i = i; } A &operator=(const A &a) = delete; A(const A &a) = delete; }; int main() { A a(1); new(&a) A(5); //a = A(7); // not allowed since = is deleted in A std::cout << a.i << std::endl; } This is a simple example using the placement new operator. Since the copy constructor and assignment operator of struct A have been deleted (for whatever reason), it is not possible to change the object the variable A a

Creating an Object in java outside of the init

此生再无相见时 提交于 2020-01-14 14:06:04
问题 so for the game I'm creating I have a few classes that extend GameDriver. Up until this point, on all the other classes I've been able to extend GameDriver and then In GameDriver I can do: ArrayList<Card> library = new ArrayList<Card>(); Today I started on the GameAI class and I extended GameDriver, and when I put: GameAI Enemy = new GameAI(); In the same spot I put the other line of code (Right below public class GameDriver) I get: java.lang.StackOverflowError at java.util.WeakHashMap

Creating an Object in java outside of the init

拜拜、爱过 提交于 2020-01-14 14:04:19
问题 so for the game I'm creating I have a few classes that extend GameDriver. Up until this point, on all the other classes I've been able to extend GameDriver and then In GameDriver I can do: ArrayList<Card> library = new ArrayList<Card>(); Today I started on the GameAI class and I extended GameDriver, and when I put: GameAI Enemy = new GameAI(); In the same spot I put the other line of code (Right below public class GameDriver) I get: java.lang.StackOverflowError at java.util.WeakHashMap

Why is __getattr__ capable of handling built-in operator overloads in python 2.x?

六眼飞鱼酱① 提交于 2020-01-14 10:48:51
问题 In python 2.x take the following class: class Person: def __init__(self, name): self.name = name def myrepr(self): return str(self.name) def __getattr__(self, attr): print('Fetching attr: %s' % attr) if attr=='__repr__': return self.myrepr Now if you create an instance and echo it in the shell (to call __repr__ ), like p = Person('Bob') p You get Fetching attr: __repr__ Bob Without the __getattr__ overload you'd have just got the default <__main__.A instance at 0x7fb8800c6e18> kind of thing.

Return array of class properties from dictionary

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-14 10:26:17
问题 Background: While recently trying to answer a question, I had myself thinking if it would be possible to return an array of class object properties directly from a dictionary item. Code: Imagine TstClass as a class module with the following code: Public val1 As Variant Public val2 As Variant Public val3 As Variant Then this code to test: Sub Test() Dim dict As Object: Set dict = CreateObject("Scripting.Dictionary") Dim lst As TstClass, key As Variant, arr As Variant For x = 1 To 3 Set lst =