Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Atom
Apr 6, 2005

by Y Kant Ozma Post
Wikipedia is opensource, why not just look at the subroutines that handle diff straight from the horse's mouth?

Adbot
ADBOT LOVES YOU

Atom
Apr 6, 2005

by Y Kant Ozma Post

Zorilla posted:

Well, the conclusion I think I just came to hours earlier (with some help) is that you should check to see if magic quotes is enabled, then either don't escape if it's on or do escape if it's off.



While I've never heard of it causing problems, it is recommended to unescape it and use the MySQL extension's escape function if magic quotes is on.

Atom
Apr 6, 2005

by Y Kant Ozma Post

Grigori Rasputin posted:

2) Have html file stubs stored on the disk to read in and print. Hits the disk, might be a slight security risk.

If this is a serious issue for you, you can use memcache or (harder to write, more optimized) write php that generates php code based on the contents of the db. The risk of somebody rewriting the .html files isn't any more than the risk of someone rewriting the code that includes it in a properly secured system.

Atom
Apr 6, 2005

by Y Kant Ozma Post

duz posted:

Or just use readfile which doesn't execute anything.

memcache doesn't execute anything either, and has a lot less overhead than reading from disk.

Atom
Apr 6, 2005

by Y Kant Ozma Post

Anveo posted:

It is stored in memory, but you have the overhead of TCP to access it, plus network latency if the server you are accessing isn't the local one.

Assuming you are reading off a local disk, access is pretty much just doing a file read, plus as a bonus is might also be cached by the OS buffers if it is frequently accessed. (Another option is a ramdisk, which is really fast, but I mention an easier option down a few sentences).

IMHO, the only time you should be using memcached is when you have multiple webservers and want a 'single' distributed cache accessed by all of them.

Bah, poo poo like this is why I prefer to use FastCGI+C. There is no reason for something like memcache to run slower than a flat file read. At least if you roll your own poo poo you know exactly how fast it's gonna be.

hallik posted:

So $bar = 'yo';
$$bar would also be accessed by $yo.

What would $$$bar be? I saw a reference to $$$bar. Would that also be $yo? Or am I forgetting something?


Yeah, I guess this is what I am asking for. I just remember seeing a question with that junk in it, and I was like huzzaah? I haven't seen that since h.s. alegbra, and haven't needed it since. It was a test to check my skills in the language, which weren't good, but I was thrown off by the exponent stuff. I don't even remember how they work. Isn't that why we have computars? I know it's good to know, but I just don't remember them, or how they are applied in PHP.

if $bar = "lol"
and $lol = "wut"
then $$$bar == $wut

Atom
Apr 6, 2005

by Y Kant Ozma Post
Quote != edit.

Atom
Apr 6, 2005

by Y Kant Ozma Post

Anveo posted:

Memcached is pretty efficient C, you just need to remember it is by design a network distributed memory cache and not a local memory cache, so it makes perfect sense it will be slower than a local file read. It is still fast and awesome.

No need to rewrite things yourself, if you mistook it for a local memory cache just use one that already exists and suggested before such as shm functions or apc.

Well yeah but still in the degenerate case of one machine in the distribution, it should just degrade into normal memory caching.

Of course, it doesn't matter anyways because we're piddling over what probably winds up being a small fraction of the execution time anyways.

:3:

Atom
Apr 6, 2005

by Y Kant Ozma Post

Zorilla posted:

One thing I've never found documentation on is what the &= assignment operator is supposed to be. Or why I sometimes see functions as ___somename(). Can somebody tell me what the purpose of these are?

&= is "bitwise AND" assignment.

$a = $a & 16;
$a &= 16;

are equivalent statements.

Functions like __function() are so-called "magic functions" and are reserved for future use by PHP. No user-defined function, constant, or method should start with "__".

e:f;b.

edit: Ha I was right though. "&=" != "=&"

Atom
Apr 6, 2005

by Y Kant Ozma Post
$a = 3;
$b = $a; //$b is a copy of $a;
$b++; //changing $b does not change $a
echo "$a != $b"; //Prints 3 != 4

$a = 3;
$b =& $a; //$b is a reference of $a;
$b++; //changing $b DOES change $a
echo "$a == $b"; //Prints 4 == 4

edit: gently caress BEATEN AGAIN YOU ASSHOLES. :mad:

Atom fucked around with this message at 01:03 on Oct 18, 2008

Atom
Apr 6, 2005

by Y Kant Ozma Post

fletcher posted:

Do you guys typically put a function that returns a collection of objects inside the class for the object it returns?

Or should it be in its own class (GetUsersResult) or something?

I do this and it works just fine for me. Makes the most sense that a function related to a certain functionality should be in the namespace of the corresponding data structure. I have no problem calling user::get_users() unless I'd be doing it some non-static way like $search_engine->get_users();

Atom
Apr 6, 2005

by Y Kant Ozma Post

fletcher posted:

Let's say you have a User class and an Article class and you want a function that returns all the articles a user has written. Does it go in the Article class as something like Article::getArticlesByUser($user) or in the User class like $user->getArticles()? What makes more sense?

I would do it the latter way. No reason to do a static function when you can have one less parameter.

Atom
Apr 6, 2005

by Y Kant Ozma Post

KuruMonkey posted:

i.e. how about 2 classes; Article and Articles; the former to abstract an individual and specific article, the second to abstract the colection of all articles, and provide functions that produce sub-collections (as, say, arrays of Article)

So you could have Articles::by_author($user_id) which returns an array[Article]...

This would then also be the logical place to put Articles::most_recent(10); and Articles::awaiting_publishing(); etc etc

(note these may well NOT actually want to be static functions, and in terms of MVC Article and Articles are both models, which give different interfaces to the same resource...)

What's the point of having a seperate class for "Articles?" I can't see what data this object would contain except that of an array of objects of type "Article"...

I fail to see the necessity of creating something like Articles::most_recent(int) when Article::most_recent(int) would make just as much sense. It seems like OOP dogma more than anything practical imho.

Atom
Apr 6, 2005

by Y Kant Ozma Post

KuruMonkey posted:

I've certainly never considered myself dogmatic about OO (slack about it, yes, dogmatic - no) I gave an answer of how I would do it, why I would do it that way, and why I wouldn't do it the other way - and a suggestion to go look at other ways - where the dogma at?

Edit; and my god I can witter on about this stuff :(

Forgive me perhaps dogma was not the correct term. I just can't see a reason for doing it that way other than for adherence to a self-imposed standard.

Atom
Apr 6, 2005

by Y Kant Ozma Post

Murodese posted:

You could always just accept arrays as input.

Yeah but if you're going to use an associative array you might as well use an object imho. I hate looking at code that takes associative arrays as input because an associative array doesn't have an explicit structure where an object does.

Adbot
ADBOT LOVES YOU

Atom
Apr 6, 2005

by Y Kant Ozma Post

Zorilla posted:

Since I don't really know for sure, can somebody more knowledgeable say how you would evaluate whether a variable assignment has succeeded or not based on whether or not $source is null? Would something like this work?

Since assignment returns the assigned value, wouldn't is_null($target = $source) work?

I have no idea why you'd want to do this however.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply