variable-names

Custom parsing function PHP

◇◆丶佛笑我妖孽 提交于 2019-12-07 13:02:40
问题 I'm trying to remove eval from the following function. I tried with sprintf and ${} , but still cannot find a solution. Here the function: function parseDbString(string $value = 'Looking for a good {{ $pippo }}'){ $pippo='Pizza'; return preg_replace_callback('/{{(.*?)}}/', function($res) use ($pippo) { // $val=${trim($res[1])}; Returns "Undefined variable: $pippo" $val=@eval("return ".trim($res[1]).";"); // Returns "Looking for a good Pizza" return isset($val) ? $val : $res[0]; },$value); }

Why doesn't these unicode variable names work with -fextended-identifiers? «, » and ≠ [duplicate]

此生再无相见时 提交于 2019-12-06 11:50:16
问题 This question already has answers here : 😃 (and other unicode characters) in identifiers not allowed by g++ (3 answers) Closed 4 years ago . I heard that it is possible to use unicode variable names using the -fextended-identifiers flag in gcc . So I made a test program in C++ but it does not compile. #include <iostream> #include <string> #define ¬ ! #define ≠ != #define « << #define » >> /* uniq: remove duplicate lines from stdin */ int main() { std::string s; std::string t = ""; while (cin

Custom parsing function PHP

只愿长相守 提交于 2019-12-05 23:08:22
I'm trying to remove eval from the following function. I tried with sprintf and ${} , but still cannot find a solution. Here the function: function parseDbString(string $value = 'Looking for a good {{ $pippo }}'){ $pippo='Pizza'; return preg_replace_callback('/{{(.*?)}}/', function($res) use ($pippo) { // $val=${trim($res[1])}; Returns "Undefined variable: $pippo" $val=@eval("return ".trim($res[1]).";"); // Returns "Looking for a good Pizza" return isset($val) ? $val : $res[0]; },$value); } So, yes, eval() is often detested as one of the highest order "evils" in php. In most cases, when a task

Is there a length limit on g++ variable names?

独自空忆成欢 提交于 2019-12-05 10:45:53
问题 See title​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​ 回答1: Short Answer: No Long Answer: Yes, it has to be small enough that it will fit in memory, but otherwise no, not really. If there is a builtin limit (I don't believe there is) it is so huge you'd be really hard-pressed to reach it. Actually, you got me really curious, so I created the following Python program to generate code: #! /usr/bin/env python2.6 import sys; cppcode=""" #include <iostream> #include <cstdlib> int main(int argc,

Variable names in Python cannot start with a number or can they?

自作多情 提交于 2019-12-05 09:14:05
问题 This is somewhat academic, but nevertheless. Python syntax forbids starting a variable name with a number, but this can be sidestepped like so: >>> globals()['1a'] = 1 >>> globals()['1a'] 1 Likewise for locals() . Does that mean that Python actually allows it, and that it's just not very visible? edit: My question is not whether it is allowed; I am aware that it is formally not allowed in Python. The question is why can I work around it by addressing globals() directly, and if that breaks

Safest way to change variable names in a project

喜夏-厌秋 提交于 2019-12-05 06:23:42
So I've been working on a relatively large project by myself, and I've come to realise that some of the variable names earlier on were.. less than ideal. But how does one change variable names in a project easily? Is there such a tool that can go through a project directory, parse all the files, and then replace the variable names to the desired one? It has to be smart enough to understand the language I imagine. I was thinking of using regexp (sed/awk on linux?) tools to just replace the variable name, but there were many times where my particular variable is also included as a part of

Does variable name length matter for performance in PHP?

这一生的挚爱 提交于 2019-12-05 05:00:24
I have been seen this Does variable name length matter for performance C#? topic and have same question about php. My co-worker (Front-end) have been encoded everything like $o, $r, $x, $m, $c and motivated it best performance. I really very doubt about it and code became difficult to read. $o - object or obj $m - $model $r - $query_result or $result $x - $xml_node Every thing look like if ( isset ( self::$o[ self::$x -> name ] ) ) : $c = 'ClassPrefix_' . self::$o[ self::$x -> name ]; $o = new $c; self::$x -> read ( ); Variable names exist more as a programmer aide - when a program or script

Why doesn't these unicode variable names work with -fextended-identifiers? «, » and ≠ [duplicate]

假装没事ソ 提交于 2019-12-04 16:47:12
This question already has answers here : 😃 (and other unicode characters) in identifiers not allowed by g++ (3 answers) Closed 4 years ago . I heard that it is possible to use unicode variable names using the -fextended-identifiers flag in gcc . So I made a test program in C++ but it does not compile. #include <iostream> #include <string> #define ¬ ! #define ≠ != #define « << #define » >> /* uniq: remove duplicate lines from stdin */ int main() { std::string s; std::string t = ""; while (cin » s) { if (s ≠ t) cout « s; t = s; } return 0; } I get these errors: g++ -fextended-identifiers -g3 -o

Am I immoral for using a variable name that differs from its type only by case?

霸气de小男生 提交于 2019-12-04 14:54:13
问题 For instance, take this piece of code: var person = new Person(); or for you Pythonistas: person = Person() I'm told constantly how bad this is, but have yet to see an example of the immorality of these two lines of code. To me, person is a Person and trying to give it another name is a waste of time. I suppose in the days before syntax highlighting, this would have been a big deal. But these days, it's pretty easy to tell a type name apart from a variable name. Heck, it's even easy to see

Non-ASCII Python identifiers and reflectivity [duplicate]

我的梦境 提交于 2019-12-04 04:54:24
This question already has answers here : Closed last year . Identifier normalization: Why is the micro sign converted into the Greek letter mu? (2 answers) I have learnt from PEP 3131 that non-ASCII identifiers were supported in Python, though it's not considered best practice. However, I get this strange behaviour, where my 𝜏 identifier (U+1D70F) seems to be automatically converted to τ (U+03C4). class Base(object): def __init__(self): self.𝜏 = 5 # defined with U+1D70F a = Base() print(a.𝜏) # 5 # (U+1D70F) print(a.τ) # 5 as well # (U+03C4) ? another way to access it? d = a.__dict__ # {'τ': 5}