How to provide default value with PHP code for a field in Views 3
You can pass currently viewing nodes id in contextual filter without using any custom code.

In contextual filter settings, under When the filter value is NOT in the URL select Provide default value option. Then there is a dropdown will show. Then select Content ID from URL. See the image: