Jump to content

ManiacDan

Staff Alumni
  • Posts

    2,604
  • Joined

  • Last visited

  • Days Won

    10

Posts posted by ManiacDan

  1. php > $s = strtotime('2012-01-01');
    php > $e = strtotime('2013-01-01');
    php > echo date('Y-m-d', ($s + $e)/2);
    2012-07-02

    Note that your math is wrong. 7/2 is halfway through the year, not 7/1. Months are not all the same length.

     

    Also, this probably won't work right on 32-bit systems.

  2. Now you're just...not making any sense.

     

    What I've learned so far:

     

    1) The code you post is not your code, there is other code that we're not seeing. This right here means you can't be helped.

     

    2) "Not working" means that in certain browsers a javascript function ("upload") isn't being called.

     

    3) You can print a DIV but not a script tag in the line right after it? Or maybe you mean everything is printing just fine and this is a javascript problem? Or...maybe?

     

    What's the current state? Both of these print statements are working as designed and specific browsers aren't executing the function? The print statements only work when there's two of them, regardless of browser? What's happening?

  3. I have nothing else after the header at this point,
    You need a die after your header regardless, and remove your ?> tag, if there's whitespace after it it could screw up other header code.

     

    As for the POST, it is valid and it is working
    You've verified that this specific post value exists in all browsers?
  4. That was a general tip about correct code, your code is still not written right because you're selecting 1 column and expecting 4.

     

    You want something like:

     

    $sql    = mysql_query("select answer FROM answers WHERE question_ID= 1 ");
    $answers = array();
    while($row      =mysql_fetch_row($sql))
    {
     $answers[] = $row[0];
    }
    echo "The answers are: " . implode(', ', $answers);

    -Dan

  5. I didn't really want to say this because I don't like giving people bad ideas, but this is a way to fake multiple inheritance or a sort of fake-y interface that doesn't require additional coding on the interfaced objects.

     

    It's still definitely weird and you shouldn't ever do it, but it's interesting, especially since it respects the invalid context and doesn't allow private/protected access. It knows that $this is another object, but uses it anyway. Such an odd choice.

  6. Programming is boring and slow. There aren't any movies about accounting either. The only thing you're going to get is movies like The Social Network or (to a significantly lesser extent) Swordfish. Few movies portray programming accurately. The Matrix trilogy portrays modern operating systems and software correctly, even going so far as to show an actual bash exploit in the third one. I can personally attest that the commands typed at the beginning of Firewall are indeed the proper way to null route an incoming IP. Later on in that movie he shoved the bare wires from a broken scanner into an iPod Mini and slapped the scanner light against a terminal, magically transforming the makeshift device into a portable OCR scanner.

     

    Computers are boring and difficult. Movies are exciting and easy. Hacking the President's Internet is the best you're going to get.

  7. Consider the following code:

     

    <?php 
    error_reporting( E_ALL | E_STRICT ); 
    class staticClass 
    { 
     function staticMethod() 
     { 
       //when called statically from the global scope, this throws a fatal error due to $this 
       echo $this->echoMe . "\n"; 
     } 
    } 
    
    class dynamicClass 
    { 
     public $echoMe; 
    
     public function __construct( $echoMe ) 
     { 
       $this->echoMe = $echoMe; 
     } 
    
     public function thisShouldNotWork() 
     { 
       //calling the staticClass method statically does NOT throw a fatal error as expected, the $this reference inside 
       //staticClass is assumed to be a reference to the current instance of dynamicClass instead 
       staticClass::staticMethod(); 
     } 
    } 
    
    $a = new dynamicClass( "Hello, World!" ); 
    $a->thisShouldNotWork(); 
    
    /* The above throws a strict warning BUT STILL PRINTS "Hello, World!" 
    Strict Standards: Non-static method staticClass::staticMethod() should not be called statically, assuming $this from incompatible context in test.php on line 22 
    Hello, World! 
    */

     

    The aptly named function thisShouldNotWork calls a method statically when that method was not defined as static. Even though the function is called statically, $this exists inside that function and can be manipulated and accessed. However, $this inside of staticClass points to a different class. No inheritance is given by the code, but one class is able to access another's variables using $this. PHP "falls back" to the last valid instance of $this since it's a super-global. Only a strict warning level will tell you that something wacky is going on.

×
×
  • 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.