Zend Unknown record property / related component Error

0

Posted by nick | Posted in PHP | Posted on Jul 17 2010

Tags:

I’ve had this troublesome error pop up twice now and the problem is not what you think. I’m working with Zend Framework and in one of my controllers I created the variable “private $_request” and with Zend Studio 7.2, I added this property to my “expressions” view to I could monitor its value. After a while I decided to no longer use that property and removed it from my code, but it was still being monitored in the expressions view of Zend Studio. That’s when the “Unknown record property / related component “$_request” on objectName” errors started. It’s not a coding error of any sort; it’s a software issue that somehow looks like a coding issue. I am using Zend Server and their debugger, so the connections between each software may be causing problems.

  • Share/Bookmark

Zend Studio php_pdo_mysql.dll error

0

Posted by nick | Posted in Development, PHP, PHPUnit, Zend Studio | Posted on Jun 29 2010

Tags: ,

I started using phpunit, which is built into Zend Studio 7.2. Everything works fine until it encountered a database query that used PDO. The test case will timeout and zend studio will give you the error “Test case was unexpectedly terminated”. It took a lot of digging to find the real error in the windows event viewer:

Faulting application name: php-cgi.exe, version: 5.2.10.10, time stamp: 0×4abb41d8
Faulting module name: php_pdo_mysql.dll, version: 5.2.10.10, time stamp: 0×4ab23077
Exception code: 0xc0000005
Fault offset: 0×00002580
Faulting process id: 0×458
Faulting application start time: 0×01cb16fb91818916
Faulting application path: C:\Program Files (x86)\Zend\Zend Studio - 7.1.0\plugins\org.zend.php.debug.debugger.win32.x86_5.3.7.v20091116\resources\php5\php-cgi.exe
Faulting module path: C:\Program Files (x86)\Zend\Zend Studio - 7.1.0\plugins\org.zend.php.debug.debugger.win32.x86_5.3.7.v20091116\resources\php5\ext\php_pdo_mysql.dll
Report Id: d31816ab-82ee-11df-99ae-00241dd93279

The solution? While I had Zend Server installed and using PHP 5.3, Zend Studio’s internal version was using PHP 5.2.xxx. I’m pretty certain Doctrine, which uses PDO, requires PHP 5.3. I changed Zend Studio to PHP 5.3 and it worked. In Zend Studio, go to Window->preferences->php->debug and ensure the “PHP executable” is set to PHP 5.3. FYI - My “server” on this screen is set to “Local Zend Server”. Hope this helps!

  • Share/Bookmark

How to install PHPUnit on Windows

2

Posted by nick | Posted in Development, PHP | Posted on Jun 18 2010

Tags:

After about ten hours of fighting with PEAR and PHPUnit, I think I have it installed correctly as my test case was able to run. There are a couple “official” documentation sources on how to install PHPUnit, but they only bother to cover installing it on linux. Further, PHPUnit has evolved quite a bit over the past few years and its configuration seems to have changed. I wouldn’t even bother installing PEAR if you don’t want to because the PHPUnit version from PEAR is grossly outdated. As of now, the currently version of PHPUnit is 3.4.9. If you install pear and phpunit from the command line as I tried a couple times, the phpunit.bat file will not be updated as it should, so phpunit will not work. If you open phpunit.bat and see these lines “set PHPBIN=”@php_bin@”
%PHPBIN% “@bin_dir@\phpunit” %*”, then you know something didn’t work right.

  1. To install manually as I did, go to http://pear.phpunit.de/get/ to download the latest version of PHPUnit. Extract the files to a directory that is listed in the include_path of your php.ini configuration file. If you’d like to place it in a custom location, add that location to the include_path in your php.ini file.
  2. Find the phpunit.bat file that you extracted, open it with a text editor and change the @php_bin@ string in it with the path to php.exe. Get rid of this line “%PHPBIN% “@bin_dir@\phpunit” %*” as it won’t be needed. On the line below, add the following line to execute phpunit.php with php ‘php -d safe_mode=Off “C:\Program Files (x86)\Zend\Apache2\htdocs\library\pear\pear\phpunit.php” %*’. Remove the single quotes I added here and change the path to phpunit.php to the file’s location on your computer (the directory you extracted phpunit to).

In the end, your phpunit.bat file should look similar to this (with that paths to php.exe and phpunit.php changed to your file locations)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
@echo off
REM PHPUnit
REM
REM Copyright (c) 2002-2010, Sebastian Bergmann <sb@sebastian-bergmann.de>.
REM All rights reserved.
REM
REM Redistribution and use in source and binary forms, with or without
REM modification, are permitted provided that the following conditions
REM are met:
REM
REM   * Redistributions of source code must retain the above copyright
REM     notice, this list of conditions and the following disclaimer.
REM 
REM   * Redistributions in binary form must reproduce the above copyright
REM     notice, this list of conditions and the following disclaimer in
REM     the documentation and/or other materials provided with the
REM     distribution.
REM
REM   * Neither the name of Sebastian Bergmann nor the names of his
REM     contributors may be used to endorse or promote products derived
REM     from this software without specific prior written permission.
REM
REM THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
REM "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
REM LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
REM FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
REM COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
REM INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
REM BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
REM LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
REM CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC
REM LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
REM ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
REM POSSIBILITY OF SUCH DAMAGE.
REM
 
set PHPBIN="C:\Program Files (x86)\Zend\ZendServer\bin\php.exe"
php -d safe_mode=Off "C:\Program Files (x86)\Zend\Apache2\htdocs\library\pear\pear\phpunit.php" %*

To test your install, go to the command line on windows and type “phpunit” and hit enter. If you don’t see any errors, then it’s installed correctly.

Other Issues
Using Zend Server 5.0, Zend framework 1.10, and PHPUnit 3.4.9, I had to apply a couple patches or bug fixes to get things to work.

  1. I received the error “Fatal error: Cannot redeclare class PHPUnit_Framework_TestCase” . The Zend Studio template for a test case automatically includes
    1
    
    require_once 'PHPUnit\Framework\TestCase.php'; .

    Change this to

    1
    
    require_once 'PHPUnit\Framework.php';

    for each test case. The bug report for this issue is located at http://framework.zend.com/issues/browse/ZF-9380

  • Share/Bookmark

Zend Framework get view directory name

0

Posted by nick | Posted in Development, PHP | Posted on Jun 04 2010

Tags:

With Zend Framework, you may have the need to know the directory name of the currently executing view script. For example, I have page nicktest.php, which uses nickTestController.php and view scripts in directory /nick-test/.  In my case, I wanted to know the name of this directory from my layout so I could include additional meta data on the page if the file existed within /nick-test/.  Unfortunately searching Google did not provide me with the answer and after hours of debugging and stepping through Zend’s MVC, I found the solution.

In your bootstrap, find where the view renderer is instantiated, like this

1
2
3
4
5
6
7
8
9
/**
 * setup the view layer
 */
public static function setupView() {
	self::$view = new Zend_View();
	self::$view->setEncoding('UTF-8');
	self::$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer(self::$view);
	Zend_Controller_Action_HelperBroker::addHelper(self::$viewRenderer);
}

Be sure to assign the $viewRenderer to self and create the public static variable within the Bootstrap class so we can access it from our layout or a controller. Then, in your controller, the below code will return “/nick-test/index.phtml” or whatever action is being processed.

1
$nameAndDirectoryOfThisPage = Bootstrap::$viewRenderer->getViewScript();
  • Share/Bookmark

The value of meaningful identifiers in variables

0

Posted by nick | Posted in Development, PHP | Posted on May 25 2010

Tags:

I found the following code today that reminded me of my first attempt at programming in college. I was having a terrible time with it and was convinced I did not want to do programming as a career. Unfortunately, the code I’d written was based off an example in a book, which looked very much like the below code I found today while at work.

function calculate_easter($y) {
	$a = $y % 19;
	$b = intval($y / 100);
	$c = $y % 100;
	$d = intval($b / 4);
	$e = $b % 4;
	$f = intval(($b + 8) / 25);
	$g = intval(($b - $f + 1) / 3);
	$h = (19 * $a + $b - $d - $g + 15) % 30;
	$i = intval($c / 4);
	$k = $c % 4;
	$l = (32 + 2 * $e + 2 * $i - $h - $k) % 7;
	$m = intval(($a + 11 * $h + 22 * $l) / 451);
	$p = ($h + $l - 7 * $m + 114) % 31;
	$EasterMonth = intval(($h + $l - 7 * $m + 114) / 31); // [3 = March, 4 = April]
	$EasterDay = $p + 1; // (day in Easter Month)
	return format_date($y, $EasterMonth, $EasterDay);
}

I can’t make heads or tails of this code and leaves me thinking the person who wrote it was either very smart or very dumb. I’d lean towards the latter.

When I asked my professor for help and showed him my program full of single letter variable names, he said “have you ever heard of meaningful identifiers?”. He should have given me a smack on the head as he said it. Today, I don’t mind writing out long variable names or functions names as long as they “meaningfully” describe the variable or function. Trust me on this - it will make code maintenance much easier in the long run and will make the lives of other developers looking at your code much less painful.

A side note - the author of the above code could have just used PHP’s built in easter_date function http://us2.php.net/easter_date .

  • Share/Bookmark