Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    neeb oop question

    I'm trying to learn some AMFPHP, no problem with that. And i've been using PHP every now and then.. OOP is new for me, so here is the function to save data to DB:

    PHP Code:
        public function save($data
        {
            
    $this->connect();

            
    $data $data->data;
            
    $data mysql_real_escape_string($data);

            
    $query "INSERT INTO $this->table (`data`) VALUES ('$data');";
            
    $result mysql_query($query);
            
    $error mysql_error();
            
    $recnum mysql_insert_id();
            
    mysql_close();

            if (
    $error
                return 
    "error: " $error;
            else  
                return 
    $recnum;
        } 
    I need to modify that to receive more args, like this:

    PHP Code:
    public function save($pid,$cid,$action,$data
    So this one is not clear for me:
    PHP Code:
            $data $data->data
    I believe thats OOP thing ..but do i need to do that for all args that im sending to this function? With "classic" php it was not necessary.

    Actually, now when i wrote this, i might have an idea:

    $data variable is coming from flashApp, and here is the code for that from flash:

    Code:
    			var byteArray:ByteArray = new ByteArray();
    			byteArray.writeObject(data);
    			byteArray.compress();
    And now im thinking ..something like.. $data variable is actually object that contains data variable? And $data->data gets that data variable, right?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    The flash look like its writing via serialize which if fairly typical of a writeObject method.
    There is no difference in the functions between a method (OOP), and a standard function. They both accept arguments in the same way. The problem you'll have is that you still need $data, which is an object.
    Since $data is an object, is it possible the extra properties you need can be found within the $data? Unfortunately, PHP does not support method overloading, so you'll need to write the signature to match every case, whether you deal with the $data as an object or as each parameter (personally I'd use $data if I could). PHP does however support typehinting which is similar to datatype handling in other languages. So you could use:
    PHP Code:
    public function myfunc(MyClassType $obj
    Which allows you to skip a step of checking if the datatype provided is valid. This only works with complex objects and 'array', but not with other types (although you can override the default error handlers to chain these - it just isn't worth doing in PHP).

    So the first thing I'd do if I were you is drop the actual insert query by commenting it out, and evaluating what the $data is by adding a var_dump($data); to see what's in it. Unfortunately, if $data itself is provided by flash, you'll need to modify the flash scripts to handle the new signatures in PHP.

  • #3
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    how can i fetch my comments in fb from my site.??

  • #4
    New Coder
    Join Date
    Nov 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for answer.

    var_dump() didnt work in this case. I got some AMF related errormsg:

    message = "faultCode:INVALID_AMF_MESSAGE faultString:'Invalid AMF message' faultDetail:

    Stack trace:
    #0 [internal function]: amfErrorHandler(2, 'Cannot modify h...', '/Users/Chelnok/...', 191, Array)
    #1 /Users/Chelnok/htdocs/bin/amfphp/core/amf/app/Gateway.php(191): header('Content-type: a...')
    #2 /Users/Chelnok/htdocs/bin/amfphp/gateway.php(162): Gateway->service()
    #3 {main}
    thrown in /Users/Chelnok/htdocs/bin/amfphp/core/amf/app/Gateway.php on line 191
    '"
    name = "Error"
    rootCause = (null)

    Is it possible to save var_dump info to file? No problems anymore, but i'm just curious what that $data contains.

  • #5
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Quote Originally Posted by Chelnok View Post
    Thanks for answer.

    var_dump() didnt work in this case. I got some AMF related errormsg:

    message = "faultCode:INVALID_AMF_MESSAGE faultString:'Invalid AMF message' faultDetail:

    Stack trace:
    #0 [internal function]: amfErrorHandler(2, 'Cannot modify h...', '/Users/Chelnok/...', 191, Array)
    #1 /Users/Chelnok/htdocs/bin/amfphp/core/amf/app/Gateway.php(191): header('Content-type: a...')
    #2 /Users/Chelnok/htdocs/bin/amfphp/gateway.php(162): Gateway->service()
    #3 {main}
    thrown in /Users/Chelnok/htdocs/bin/amfphp/core/amf/app/Gateway.php on line 191
    '"
    name = "Error"
    rootCause = (null)

    Is it possible to save var_dump info to file? No problems anymore, but i'm just curious what that $data contains.
    Yes.

    PHP Code:
    ob_start();
    var_dump($data);
    $varDumpString ob_get_clean(); 
    That will capture the result from var_dump before it sends it to the browser and you can capture it off into a string and print it out later or save it off to a file if you wish.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #6
    New Coder
    Join Date
    Nov 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That is very handy function! Cant believe i havnt ever stumble upon it.


    edit:
    ByteArray object looks like this:
    object(ByteArray)#8 (1) {
    ["data"]=>
    string(171) " -here is the binary data- "}
    Last edited by Chelnok; 11-07-2011 at 08:31 PM. Reason: just ..btw :)


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •