Call to a member function getArrayCopy() on a non-object

248 views
Skip to first unread message

Bob

unread,
Jun 3, 2009, 12:28:36 AM6/3/09
to Outlet ORM
Hi,

I am recieving this error in 0.7:
Fatal error: Call to a member function getArrayCopy() on a non-object
in <app path>/outlet/OutletMapper.php on line 201.

I will be grateful for any ideas about this.
Thanks

Fabio R.

unread,
Jun 3, 2009, 2:05:23 AM6/3/09
to outle...@googlegroups.com
Hi Bob,
 
Would you be able to send us the code for entities and config?
 
 
Regards,
--
Fábio Rehm

Bob

unread,
Jun 3, 2009, 2:36:40 AM6/3/09
to Outlet ORM
Hi Fabio,

Thanks for your quick reply.

When I posted this error, I hadn't read the post about using the
Collection object instead of array in 0.7 (I was working from the
Quick Start guide, which still says to use arrays for *-to-many
relationships). I have made the changes to my code.
However, I am still getting what I think is a related error, whenever
I try to use the add() method on the Site::$pages Collection:
"Fatal error: Call to a member function add() on a non-object"

I suspect that I need to initialize the Site::$pages variable somehow,
so that it is a Collection and not null.

I am still in early stages of implementing my app using Outlet, but
here is my code so far.

Here are the entities, Site and Page:
<?php
class Site
{
public $ID;
public $SiteID;
public $Name;

private $pages; // somehow I need to initialize this??

public function getPages() { return $this->pages; }
public function setPages(Collection $pages) { $this->pages =
$pages; }
public function addPage(Page $page) { $this->pages->add($page); }
}

<?php
class Page
{
public $ID;
public $Name;
public $Description;

private $site;

public function getSite() { return $this->site; }
public function setSite(Site $site) { $this->site = $site; }
}

And here is my configuration:
<?php
return array
(
"connection" => <...>,
"classes" => array
(
"Site" => array
(
"table" => "sites",
"props" => array
(
"ID" => array("id", "int", array("pk" => true,
"autoIncrement" => true)),
"Name" => array("name", "varchar")
),
"associations" => array
(
array("one-to-many", "Page", array("key" => "SiteID"))
)
),
"Page" => array
(
"table" => "pages",
"props" => array
(
"ID" => array("id", "int", array("pk" => true,
"autoIncrement" => true)),
"SiteID" => array("site_id", "int"),
"Name" => array("name", "varchar"),
"Description" => array("description", "varchar")
),
"associations" => array
(
array("many-to-one", "Site", array("key" => "SiteID"))
)
)
)
);

Thanks,
Bob

Bob

unread,
Jun 3, 2009, 2:44:55 AM6/3/09
to Outlet ORM
Quick update:

I've added a constructor to the Site class to initialize the $pages
Collection, like so
function __construct() { $this->pages = new Collection; }
It seems to work.

I wonder if there is a way to add this initialization to the backend
somehow, so it doesn't need to be done for every entity.
Or, maybe I am missing the point somewhere and there is a better way
to do this?

phpe...@gmail.com

unread,
Jun 4, 2009, 12:54:29 PM6/4/09
to Outlet ORM
It was testing outlet but it gave the same problem that the user in
post previous cited

http://www.outlet-orm.org/wiki/index.php/Quick_Start_Guide#Usage

Call to a member function getArrayCopy() on a non-object

class Project {
public $ID;
public $Name;

private $bugs = array();


public function getBugs () {
return $this->bugs;
}

public function setBugs ($bugs) {
$this->bugs = $bugs;
}

public function addBug (Bug $bug) {
$this->bugs = $bug;
}
}


class Bug {
public $ID;
public $Title;
public $ProjectID;
public $Description;

private $project;

public function getProject () {
return $this->project;
}

public function setProject (Project $project) {
$this->project = $project;
}
}


<?php
return array(
'connection' => array(
'dsn' => 'mysql:hostname=localhost;dbname=sie',
'username' => 'root',
'password' => '',
'dialect' => 'mysql'

),

// map each class and their properties to their corresponding tables
and columns
// also map the associations between classes
'classes' => array(
'Project' => array(
'table' => 'projects',
'props' => array(
'ID' => array('id', 'int', array('pk'=>true,
'autoIncrement'=>true)),
'Name' => array('name', 'varchar')
),
'associations' => array(
array('one-to-many', 'Bug', array('key'=>'ProjectID'))
)
),
'Bug' => array(
'table' => 'bugs',
'props' => array(
'ID' => array('id', 'int', array('pk'=>true,
'autoIncrement'=>true)),
'Title' => array('title', 'varchar'),
'ProjectID' => array('project_id', 'int'),
'Description' => array('description', 'varchar')
),
'associations' => array(
array('many-to-one', 'Project', array('key'=>'ProjectID'))
)
)
)
);


Alvaro Carrasco

unread,
Jun 4, 2009, 5:05:17 PM6/4/09
to outle...@googlegroups.com
phpe...@gmail.com wrote:
> It was testing outlet but it gave the same problem that the user in
> post previous cited
>
> http://www.outlet-orm.org/wiki/index.php/Quick_Start_Guide#Usage
>
> Call to a member function getArrayCopy() on a non-object
>
>
...


Sorry, when releasing the 0.7 release i forgot to update the quick start
guide.
You now have to initialize the collections in constructor since php does
not allow property initialization using an object at definition, like
Bob found out:

class Project {
protected $bugs;
function __construct () {
$this->bugs = new Collection();
}

...
}

I have updated the guide with the new approach.

Alvaro

phpe...@gmail.com

unread,
Jun 5, 2009, 11:03:00 AM6/5/09
to Outlet ORM
thanks,

after saving one obtect as to recoup id to save in another object?

On 4 jun, 18:05, Alvaro Carrasco <alv...@epliant.com> wrote:
Reply all
Reply to author
Forward
0 new messages