Archivio

Archivio per la categoria ‘Programmazione’

How to configure Xdebug on Ubuntu with Zend Server

17 febbraio 2011 Nessun commento

I assume you have properly installed and configured Zend Server CE from the repository.

First of all you need to install automake:

sudo apt-get update && sudo apt-get upgrade
sudo apt-get install automake

Install Xdebug with PECL as root:

# pecl install xdebug

Note: if you don’t have PECL in your path you can prepend the absolute path before the command

# /usr/local/zend/bin/pecl install xdebug

Now you must edit php.ini file.

sudo nano /usr/local/zend/etc/php.ini

Add these lines at the end of file:

; Xdebug
zend_extension = /usr/local/zend/lib/php_extensions/xdebug.so
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000

Note: Xdebug is incompatible with theZend Debugger extension. To disable this component you can log into Zend Server control page at https://localhost:10082 and navigate to tab Server Setup > Components then turn off Zend Debugger. Remember to click the Restart PHP button to apply the changes.

Links:

Call-time pass-by-reference has been deprecated

19 febbraio 2010 Nessun commento

If you recently upgraded PHP to version 5.3.0 or higher, you have probably encountered a message like this:

Deprecated: Call-time pass-by-reference has been deprecated in filename.php

Use & when you call a function foo(&$var) generates the warning message.

Remember that in 5.3 version of PHP only Call-time pass by reference is deprecated but not Passing by reference.

See the example below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// normal passing by reference
function functionA(&$var) {
    $var++;
}
 
// call-time passing by reference
function functionB($var)
{
    $var++;
}
 
// correct call
functionA($var);
 
// deprecated
functionB(&$var);

If you can’t edit existing code, for example, third-party software, you can use these work-arounds:

  1. Turn off error messages: is always a good idea hide any type of error message in a production site. You can use error_reporting(0) function or if you want you can use the @ symbol before any statement. This is not a good solution of this problem.
  2. Allow call-time pass-by-reference in your php.ini file: in your php.ini file you can set allow_call_time_pass_reference = on but this is a temporary solution only until the next version.

Resources:

UTF-8 problem with Spreadsheet Excel Writer

27 gennaio 2010 Nessun commento

Spreadsheet Excel Writer is a PEAR package that allows you to generate Excel documents.

When we try to generate an new Excel document using UTF-8 string we ran into a display error.

There is a simple way to fix this problem. See the example below:

$workbook = new Spreadsheet_Excel_Writer();
$workbook->send("file.xls");
 
// add this row
$workbook->setVersion(8);
 
$worksheet =& $workbook->addWorksheet("My worksheet");
 
// add this row
$worksheet->setInputEncoding("UTF-8");
 
$workbook->close();

Create a PHP data structure accessible like an array and an object simultaneously

26 gennaio 2010 Nessun commento

Often we need to operate with objects that sometimes we have to use as an array.
For example we can get an attribute from an object:

$attr = $myObject->attr;

or by array access from the same object

$attr = $myObject['attr'];

We can set data simply like an array or directly.

Categorie:PHP, Programmazione Tag: , ,