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
Inquisitus
Aug 4, 2006

I have a large barge with a radio antenna on it.

fletcher posted:

What's the point of declaring public variables in a class? If I remove them all, my application will behave the same, correct?

php:
<?
class User {
    public $id;
    public $username;
}
?>

Not quite sure what you mean by that.

Basically public fields are accessible from any code:

php:
<?
class Foo
{
    public $baz;
}

class Bar
{
    private $baz;
}

$foo = new Foo;
$bar = new Bar;

$foo->baz = 'baz'; // No problem here.
$bar->baz = 'baz'; // Fatal error!
?>
Edit: Unless you mean what's the point in the public modifier itself… It's just there for consistency and so that you can be explicit about it. If you want a member to be public, then declare it as such.

Inquisitus fucked around with this message at 19:57 on Mar 28, 2008

Adbot
ADBOT LOVES YOU

Inquisitus
Aug 4, 2006

I have a large barge with a radio antenna on it.

duz posted:

You're supposed to use braces when you want the contents of a variable.

php:
<?
$string = "The quick {$data['colour']} fox jumps over the lazy dogs."
?>

Alternatively:
php:
<?
$string = "The quick $data[colour] fox jumps over the lazy dogs."
?>

Inquisitus
Aug 4, 2006

I have a large barge with a radio antenna on it.

MononcQc posted:

Adding braces around $array[$value[1]] to get {$array[$value[1]]} was the best way to get the arrays to work properly.

PHP :eng99:

Inquisitus
Aug 4, 2006

I have a large barge with a radio antenna on it.

nbv4 posted:

I have this one class which is getting so huge, it's almost 2000 lines. I want to split it up into smaller text files to make editing easier, but I'm having trouble doing so. Apparently you can't just do:

php:
<?

class foo extends lol
{
     include "text_file_with_methods.php";

     function blah()
     {
       ...
?>
nor can you have a class extending from multiple classes. What can I do here?

Either try and split the class up logically into smaller classes, or leave it as it is if you can't.

Inquisitus
Aug 4, 2006

I have a large barge with a radio antenna on it.
If you don't like ORM then PEAR::MDB2 might be worth having a look at.

Actually an ORM layer is far better suited to your needs.

Inquisitus fucked around with this message at 09:51 on Apr 10, 2008

Inquisitus
Aug 4, 2006

I have a large barge with a radio antenna on it.

LOL AND OATES posted:

if cURL isn't enabled, use file_get_contents:
php:
<?php
$file file_get_contents'http://path/.jpg' );
header'Content-Type: image/jpeg' ); 
echo $file;
?>


Or just readfile it:

code:
<?php
header("Content-Type: image/jpeg\r\n"); 
readfile('http://path/.jpg');
?>

Inquisitus
Aug 4, 2006

I have a large barge with a radio antenna on it.

gibbed posted:

Drop the trailing ?> too, there is no need for it in this script.

code:
<?php
header('Content-Type: image/jpeg');
readfile('http://path/.jpg');

That's just taking it too far :colbert:

gibbed posted:

Edit: wait why the hell did you put a \r\n in the header() call?

That was me getting confused between header and mail (which I'd just been using and takes headers as a string, hence needing line breaks).

Inquisitus
Aug 4, 2006

I have a large barge with a radio antenna on it.
You need to put quotes around associative array indices:

php:
<?
if ($getclub['private'] == 1)
{
    // ...
}

// ...

if ($getmemberdata4['id'])
{
    // ...
}
?>

Inquisitus
Aug 4, 2006

I have a large barge with a radio antenna on it.
:siren: MVC theory question: :siren:

I'm currently playing around with the Propel ORM framework and trying to work out how best to integrate it into Kohana (an MVC framework). My question is how should I go about transforming Propel's generated data objects when they're passed through the controller and into the view? Leaving them as they are would be exposing details of the data layer to the presentation layer, but constructing a new object for each one seems completely over the top.

Not sure how to proceed; please advise!

Inquisitus
Aug 4, 2006

I have a large barge with a radio antenna on it.

duck monster posted:

Back a whole bunch of pages was the question "How to stop image leeching".

Do this;- Compress 1 gig of zeros into a file named "image.jpg.gz". It'll come down to a megabyte.

Use url redirect and some magic to serve that as a gzip encoded http stream instead when the referer is all wrong.

Being that this satanic son of a bitch memory-murders anything that tries to leech it, the leeching stops very loving quickly.

:eng101: This is also a good way to massacre bots that ignore your robots.txt

put in something like dont_download_me_or_yourbrowser_will_die.html which is actually the browser bomb in your robots, and watch as spam spiders die screaming (some, not all, some will use smarter stream tech and not die.)

I like this idea :clint:

Inquisitus
Aug 4, 2006

I have a large barge with a radio antenna on it.

hallik posted:

I have been looking around, but can't find a good explanation of using multiple $$$

Like why would you have $$var1 or $$$var2? Please explain or point me to a place that explains it.

Basically $$foo takes the value in the variable $foo and uses it as a variable name for accessing the another variable (this is what the first $ is doing). So if $foo had the value of "baz", then PHP would just access $baz.

hallik posted:

Or how about how math is done with the e^ stuff. (Sorry if this isn't clear. I was taking some online tests, and have never had to use exponents or that ^, but it wanted me to know)

Not really sure what's being asked here. Are you asking how exponentials are computed algorithmically?

Inquisitus
Aug 4, 2006

I have a large barge with a radio antenna on it.

hallik posted:

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.

You really don't need to know how exponentials are actually computed at the algorithmic level. I don't know myself, but I imagine it'd be something to do with Taylor expansions.

If you just want to get the result of an exponential with base e, then use PHP's exp function.

Inquisitus fucked around with this message at 10:05 on May 11, 2008

Inquisitus
Aug 4, 2006

I have a large barge with a radio antenna on it.
Can anyone think of a way to detect whether a class is abstract in PHP? I don't care if it's kinda hacky just as long as it's fool-proof and preferably doesn't involve digging into the source itself :shobon:

Edit: reflection duh :downs:

Inquisitus fucked around with this message at 15:25 on Aug 5, 2008

Adbot
ADBOT LOVES YOU

Inquisitus
Aug 4, 2006

I have a large barge with a radio antenna on it.

Mine GO BOOM posted:

Hashing a hash only increases the chance of collisions and doesn't make it more secure.

For a salt, in PHP, I just use sha1(uniqid(mt_rand(), true).

Collisions aren't a problem if you're salting; the point is that hashing that many times would gently caress up rainbow tables since they'd take millennia to generate and bruteforcing would also be slow as poo poo.

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