Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 09-14-2011, 05:17 AM class permissions
numbenator's Avatar
Webmaster Talker

Posts: 523
Location: London
Trades: 0
Hi

I have put together a class IE a user class.

My class requires to use functionality from another class but i dont want to extend one from the other

Is this possible ( or do i have to extend or pass as parameter in construct ) and if so how do i code this in.

IE

Code:
$facebook = new Facebook(array(
  'appId' => 'xxxxxxxx',
  'secret' => 'yyyyyyyyyyyyyyy',
  'cookie' => true,
  ));

class User {

   private $friends=array();

   function someFunction() {
 

     // i want to execute $facebook->api

    $this->friends=$facebook->api('/'.$uid.'/friends', 'get', array('access_token' => $signed_request['oauth_token']));

  }


}

Cheers

Steve
__________________

Please login or register to view this content. Registration is FREE
numbenator is offline
Reply With Quote
View Public Profile Visit numbenator's homepage!
 
 
Register now for full access!
Old 09-14-2011, 06:29 AM Re: class permissions
vectorialpx's Avatar
Extreme Talker

Posts: 249
Name: octavian
Location: Bucharest
Trades: 0
PHP Code:
<?php
function someFunction() {
    global 
$facebook;
    
// i want to execute $facebook->api
    
$this->friends $facebook...
?>
__________________
you can
Please login or register to view this content. Registration is FREE
vectorialpx is offline
Reply With Quote
View Public Profile Visit vectorialpx's homepage!
 
Old 09-14-2011, 07:37 PM Re: class permissions
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
So long as facebook is defined before you create an instance of your user class you can assign a reference to it in the constructor:

PHP Code:
class User {

   private 
$friends=array();
   private 
$facebook;

   public function 
__construct()
   {
        global 
$facebook;
        
$this->facebook = &$facebook;
   }

   function 
someFunction() {
 

     
// i want to execute $facebook->api

    
$this->friends=$this->facebook->api('/'.$uid.'/friends''get', array('access_token' => $signed_request['oauth_token']));

  }



__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Reply     « Reply to class permissions
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.12127 seconds with 12 queries