NYCPHP Meetup

NYPHP.org

[nycphp-talk] Help with a self:: ish problem

Jake McGraw jmcgraw1 at gmail.com
Thu Dec 6 10:08:24 EST 2007


Have you tried using a callback?

If the function name passed to do_action is declared within the current
object you should be able to perform the following:

call_user_func($this,'update');

Check out the section on callbacks:

http://us.php.net/callback

and the function call_user_func:

http://us.php.net/manual/en/function.call-user-func.php

- jake

On Dec 6, 2007 9:58 AM, Rick Retzko <rick at click-rick.net> wrote:

>  Gents/Ladies -
>
> Some help please with my PHP5 OOP learning curve:
>
> I'm trying to use a $this variable to call a function within a class.  I
> know the following works:
>
> class actions {
>
>  private $_aData;
>  private $_table;
>
>  public function __construct(){
>     $this->_aData=array();
>     $this->_table=FALSE;
>  }
>
>  private function update(){
>   echo 'Update being executed!';
>   return TRUE;
>  }
>
> //public functions ==================================
>     public function do_action($table,$data){
>      //direct action activity
>      //assumption: $data['action'] will contain action definition
>      $this->_table=$table;
>      $this->_aData=$data;
>
>      $completed=self::update();  //<==  THIS IS THE PROBLEM LINE
>
>      return $completed;
>
>     }
> }
>
> When I change that line to
> "$completed=self::$this->_aData['action'].'()';"  (which contains the string
> 'update'), the line is read, but nothing happens.
> When I add "$action=$this->_aData['action'].'()';", then change the line
> to "$completed=self::$action;", I get the following error message:
> *Fatal error*: Access to undeclared static property: actions::$action in *C:\Program
> Files\Apache Software
> Foundation\Apache2.2\htdocs\cjmea\hs_choir\classes\class.actions.php5* on
> line *37.*
> **
> All help is appreciated!
>
>
> Best Regards -
>
> Rick
> rick at click-rick.net
>
>
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20071206/d2f7f022/attachment.html>


More information about the talk mailing list