Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-04-2011, 08:43 PM   PM User | #1
Chelnok
New Coder

 
Join Date: Nov 2011
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Chelnok is an unknown quantity at this point
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?
Chelnok is offline   Reply With Quote
Old 11-04-2011, 10:56 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,658
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 11-05-2011, 01:44 PM   PM User | #3
innpacked
New to the CF scene

 
Join Date: Jul 2011
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
innpacked is an unknown quantity at this point
how can i fetch my comments in fb from my site.??
innpacked is offline   Reply With Quote
Old 11-06-2011, 10:19 PM   PM User | #4
Chelnok
New Coder

 
Join Date: Nov 2011
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Chelnok is an unknown quantity at this point
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.
Chelnok is offline   Reply With Quote
Old 11-06-2011, 11:27 PM   PM User | #5
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,223
Thanks: 4
Thanked 80 Times in 79 Posts
Spookster will become famous soon enough
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
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline   Reply With Quote
Old 11-07-2011, 08:20 PM   PM User | #6
Chelnok
New Coder

 
Join Date: Nov 2011
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Chelnok is an unknown quantity at this point
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 :)
Chelnok is offline   Reply With Quote
Reply

Bookmarks

Tags
function, oop, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:10 PM.


Advertisement
Log in to turn off these ads.