Jump to content

Goat

Members
  • Posts

    63
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

Goat's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. While I agree that the idea is highly impractical in PHP, I strongly disagree that it is "incredibly stupid". For one, the whole of human genome is encoded in just one language, DNA, and that's a more complex machine than anything you and I are bashing together. It is more likely that our approach is ultimately stupid even if it works better short-term. But more seriously, all else being equal, it is better to have a tree representation of a language instead of string representation. Imagine if jQuery conceptualized HTML as one giant string instead of as annotated tree? For that matter, why not have server side jQuery? It would be convenient to transform some html server side for the same reason it is convenient to do it client side. Anyway I can think of some good reasons why one would want to have SQL as three (provided we had concise syntax for building the tree, which we don't) : 1. eliminate all sql injections. You would recursively traverse the whole tree and escape all strings. 2. enable creating sql query from multiple sources. Imagine that you have huge amount of filtering functions and all of them are controlling what rows from a table can be displayed based on user level, age, preferences and, hell, ear size. It would be more practical for every function to return tree fragment that is eventually programatically combined into one giant WHERE statement than to assemble one giant sql string by hand. It is not that there are no reasons to do this. It is that it is probably not worth it in PHP. Yeah I agree that I have cheated and that it would have been even longer to do properly.
  2. Well it is integral flaw of all languages except lisp . Now, I don't want to evangelize for lisp - the language has some massive flaws, most important being fragmented (and frankly arrogant) community and bunch of incompatible implementations. It frankly deserves to be marginalized. Nevertheless having something like s-expressions would be a great help as then you can represent foreign languages in tree form instead of gluing together bunch of strings. My s-expressions MySQL example doesn't require programmer to manually apply mysql_real_escape_string, as you can write a macro that will slap it on every variable. That's certainly convenient. So would be ability to traverse HTML nodes. PHP sorta tries to have some of those advantages with its array syntax, but only gets there halfway. I was inspired to try something like this by reading the Emacs problem. But I don't want to get on this soapbox as I might get lynched.
  3. In case you guys don't know what lisp is, tl;dr is that is an old language without syntax that uses polish notation and parentheses to represent all language constructs. You can also create your own language constructs. For example, this mysql statement : UPDATE table_name SET column1=value1,column2=value2 WHERE some_column=some_valueCan be represented as (update "table_name" (set ('column1 "value1") ('column2 "value2") (where (= some_column "some_value")))One advantage of this whole thing is that you don't have to mix multiple languages to create a site. When you program in php, you actually use html, css, php and MySQL. When you program in lisp, you only use lisp. Another advantage is that the language with no syntax is easier to programaticaly generate than one with it. I can auto generate various sql statements as lisp trees. The disadvantage is that lisp is obscure as hell and no one uses it. So I was thinking of using php arrays to get some of that expressiveness of lisp in PHP and to abstract away necessity to glue together sql strings. So far it has been mixed results. One way to represent update is this ["update", "table_name", ["column1" => "value1", "column2" => "value2"], ["where", [ "=", "some_column", "some_value"]]]I represent columns to be updated as key=>value pairs since column names are unique anyway. One advantage of this method is that I don't have to use mysql_real_escape_string on variables for updating. My interpreter automatically escapes everything inside SET bracket and adds quotes to values. This is however, less than practical in its WHERE part. That's because it is less clear what part you can and can't escape, since column names, functions and values can all be mixed up in WHERE part, and arrays are not nearly as flexible as s-expressions. Anyone has any idea how best to do this?
  4. Thanks for your answer. I was aware of all that. I agree. That's why my example says get_parent($ref, $some_array). I knew that reference alone just knows about the string, not the places where that string might be. Well that's a bummer. I really expected PHP to have some way of comparing two references to see if they contain the same value. It kinda sucks that it doesn't. Yeah some sort of breadcrumb secondary array seems like the only hope then. Maybe I should create a class called browseable_array or something that has main array, breadcrumb array and parent/sibling/child methods in it? Has anyone else done something similar? Is there some other nested datatype in PHP that I can use? Maybe convert array to an XML object, assuming PHP XML api has the functionality I need (I never tried using XML in php)? Thanks for taking interest.
  5. Thanks for answering, but are you sure about that? I don't know how exactly references look like in the memory, but if reference contains a pointer to '__smth' then it should be possible to recursively find value with the same pointer in the array. In fact I can create such function myself if someone can provide a syntax for checking if a reference and a variable point to the same value.
  6. No, sorry, it was not, I was trying to edit post, but I hit quote accidentally, And I couldn't find delete post in this new interface. I hope admin can delete my post.
  7. Lets say that we have several nested arrays, like in this example: $some_array = array( 'key_foo' => 'var_foo', 'key_bar' => array( '_key_baz' => '_smth' '_key_other_baz' => array( '__key_some_foo' => '_foo_2', '__key_some_other_foo' => '_foo_3', '__key_some_other_foo' => '_quix' ) ) 'key_quux' => 'var_foo_3', 'key_baz' => array( '_key_smt' => '_quix_2' ) ); Let's also say that we have a reference: $ref = &$some_array['key_bar']['_key_baz']; Is it possible to, using that reference and that array, to find out what siblings, parents and children '_smth' has? I want some functionality like this: get_parent($ref, $some_array) // returns a reference to 'key_bar' get_next_sibling($ref, $some_array) // returns a reference to '_key_other_baz' You get the idea. Does php have some out of the box functionality like that or it has to be manually implemented via recursively searching for reference? Thanks for reading.
  8. I suggest you tackle it as MySQL query problem, not as php problem. It is possible to merge multiple arrays but I suggest you create query that returns already merged array that you want. Google something called LEFT JOIN and RIGHT JOIN to find out how to get values from multiple tables. regards, Goat
  9. There's probably more elegant regex solution, but this works: $username = preg_replace("/[\.,\";'\:]/", "", $domain); if( is_numeric(substr($username, 0, 1)) ) { $username .= 't'.$username; } $username = substr($username, 0, ; regards, Goat
  10. Thanks, PFMaBiSmAd . Now I feel somewhat stupid for not trying that right away . regards, Goat
  11. look at this code <?php mysql_connect(yadda yadda yadda); mysql_select_db(yadda yadda); $arr = mysql_fetch_assoc(mysql_query('SELECT yadda yadda')); if($arr['timestamp']<=$_REQUEST['timestamp']) { die(); // big_file.php never gets included and is thus never interpreted, speeding up script a little } else { $a='big_file.php'; // cheats interpeter so it doesn't know right away we want big_file.php include($a); // now that we actually need big_file.php , it gets included, interpreted and executed } ?> Sorry if I misunderstood you (and you are rather knowledgeable guy so I wouldn't want to), but you seem to be saying that interpreter will find out ahead of time (before getting to else part) that I am including big_file.php and convert it to byte-code (thus needlessly slowing down execution when that slice of code is unnecessary).
  12. Interpreter can't figure out ahead of time (unless it has AI in it or something) that you want to include big_file.php, therefore it can't interpret that file until it gets to it. Therefore, script from OP will die without interpreting that file unless that file is really needed. Which is exactly what I wanted to do in the first place.
  13. Well now I figured how to do that without eval. See second post .
  14. Wait, I don't even need eval, just variable in include, like this: $a = 'big_file.php'; include($a); well, I hope this is useful to someone else, too
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.