doujiurong7210 2016-10-19 02:40
浏览 52

无法序列化和反序列化对象以删除对象元素PHP

Getting an instance like this:

$coreBootstrap = new PEP_Application_BootstrapCore(array('bootstrap' => $this));

Receives this object:

PEP_Application_BootstrapCore Object ( [_bootstrap:protected] => Bootstrap Object ( [_appNamespace:protected] => [_resourceLoader:protected] => [_application:protected] => PEP_Application Object ( [_autoloader:protected] => PEP_Autoloader Object ( [_autoloaders:protected] => Array ( [0] => Zend_Application_Module_Autoloader Object ( [_basePath:protected] => C:\LodgingPhp\com-ui-php\target\packaged-application\application [_components:protected] => Array ( [Default_Controller_Action_Helper] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/controllers/actions/helpers [Default_Module] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/modules [Default_Model_DbTable] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models/DbTable [Default_Model_Mapper] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models/mappers [Default_Form] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/forms [Default_Model] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models [Default_Plugin] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/plugins [Default_Service] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/services [Default_View_Helper] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/views/helpers [Default_View_Filter] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/views/filters ) [_defaultResourceType:protected] => model [_namespace:protected] => Default [_resourceTypes:protected] => Array ( [actionhelper] => Array ( [namespace] => Default_Controller_Action_Helper [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/controllers/actions/helpers ) [module] => Array ( [namespace] => Default_Module [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/modules ) [dbtable] => Array ( [namespace] => Default_Model_DbTable [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models/DbTable ) [mappers] => Array ( [namespace] => Default_Model_Mapper [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models/mappers ) [form] => Array ( [namespace] => Default_Form [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/forms ) [model] => Array ( [namespace] => Default_Model [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models ) [plugin] => Array ( [namespace] => Default_Plugin [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/plugins ) [service] => Array ( [namespace] => Default_Service [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/services ) [viewhelper] => Array ( [namespace] => Default_View_Helper [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/views/helpers ) [viewfilter] => Array ( [namespace] => Default_View_Filter [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/views/filters ) ) ) ) [_defaultAutoloader:protected] => Array ( [0] => PEP_Loader [1] => loadClass ) [_fallbackAutoloader:protected] => [_internalAutoloader:protected] => Array ( [0] => PEP_Autoloader Object *RECURSION* [1] => _autoload ) [_namespaces:protected] => Array ( [Zend_] => 1 [ZendX_] => 1 [WDPRO_] => 1 [PEP_] => 1 [controllers_helpers_] => 1 [Guzzle] => 1 [Symfony] => 1 ) [_namespaceAutoloaders:protected] => Array ( [Default_] => Array ( [0] => Zend_Application_Module_Autoloader Object ( [_basePath:protected] => C:\LodgingPhp\com-ui-php\target\packaged-application\application [_components:protected] => Array ( [Default_Controller_Action_Helper] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/controllers/actions/helpers [Default_Module] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/modules [Default_Model_DbTable] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models/DbTable [Default_Model_Mapper] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models/mappers [Default_Form] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/forms [Default_Model] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models [Default_Plugin] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/plugins [Default_Service] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/services [Default_View_Helper] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/views/helpers [Default_View_Filter] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/views/filters ) [_defaultResourceType:protected] => model [_namespace:protected] => Default [_resourceTypes:protected] => Array ( [actionhelper] => Array ( [namespace] => Default_Controller_Action_Helper [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/controllers/actions/helpers ) [module] => Array ( [namespace] => Default_Module [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/modules ) [dbtable] => Array ( [namespace] => Default_Model_DbTable [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models/DbTable ) [mappers] => Array ( [namespace] => Default_Model_Mapper [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models/mappers ) [form] => Array ( [namespace] => Default_Form [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/forms ) [model] => Array ( [namespace] => Default_Model [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models ) [plugin] => Array ( [namespace] => Default_Plugin [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/plugins ) [service] => Array ( [namespace] => Default_Service [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/services ) [viewhelper] => Array ( [namespace] => Default_View_Helper [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/views/helpers ) [viewfilter] => Array ( [namespace] => Default_View_Filter [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/views/filters ) ) ) ) ) [_suppressNotFoundWarnings:protected] => [_zfPath:protected] => ) [_bootstrap:protected] => Bootstrap Object *RECURSION* [_environment:protected] => local [_optionKeys:protected] => Array ( [0] => phpsettings [1] => includepaths [2] => bootstrap [3] => resources [4] => deviceprofiling [5] => pluginpaths [6] => autoloadernamespaces ) [_options:protected] => Array ( [phpSettings] => Array ( [log_errors] => 1 [date] => Array ( [timezone] => America/New_York ) [display_startup_errors] => 0 [display_errors] => 1 [error_reporting] => 32767 [error_log] => C:\LodgingPhp\com-ui-php\target/logs/php_error.log ) [includePaths] => Array ( [library] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/../library ) [bootstrap] => Array ( [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/Bootstrap.php [class] => Bootstrap ) [resources] => Array ( [frontController] => Array ( [controllerDirectory] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/controllers [moduleDirectory] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/modules ) [layout] => Array ( [layoutPath] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/layouts/scripts ) [setsystemtime] => Array ( [load] => ) [session] => Array ( [strict] => ) [modules] => Array ( [0] => api [1] => tickets [2] => events [3] => passes [4] => plan [5] => resortaddons [6] => debugutils [7] => visa-instant-credit ) [view] => [log] => Array ( [logConfig] => /configs/log.ini ) [stats] => Array ( [serviceLogLevel] => INFO [requestResponseLogLevel] => DEBUG [viewLogLevel] => INFO [actionLogLevel] => INFO [appLogLevel] => INFO [memoryLogLevel] => DEBUG ) [serviceSuccessLog] => Array ( [logConfig] => /configs/serviceSuccessLog.ini ) ) [deviceprofiling] => Array ( [cookieName] => WDPROView [timeToLive] => 604800 [cookiePath] => / [enabled] => 1 [routeBlackList] => Array ( [0] => /api [1] => /utils ) ) [pluginpaths] => Array ( [PEP_Stats_Resource_] => PEP/Stats/Resource [PEP_Application_Resource_] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/../library/PEP/Application/Resource [Default_Resource_] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/resource ) [autoloadernamespaces] => Array ( [0] => WDPRO_ [1] => Zend_ [2] => PEP_ [3] => controllers_helpers_ [4] => Guzzle [5] => Symfony ) ) ) [_classResources:protected] => Array ( [autoload] => _initAutoload [core] => _initCore [router] => _initRouter [servicestub] => _initServiceStub [mediaengineconfig] => _initMediaEngineConfig [viewhelpers] => _initViewHelpers [configurablestoreplugin] => _initConfigurableStorePlugin [languagesetupplugin] => _initLanguageSetupPlugin [keywordrouterplugin] => _initKeywordRouterPlugin [tripconfig] => _initTripConfig [dclkeepalive] => _initDclKeepAlive [helpconfig] => _initHelpConfig [analyticsgenericplugin] => _initAnalyticsGenericPlugin [postdispatchstatsdplugin] => _initPostDispatchStatsDPlugin [curoauthplugin] => _initCUROAuthPlugin [sessionserviceshdrplugin] => _initSessionServiceShdrPlugin ) [_container:protected] => Zend_Registry Object ( [storage:ArrayObject:private] => Array ( [autoload] => Zend_Application_Module_Autoloader Object ( [_basePath:protected] => C:\LodgingPhp\com-ui-php\target\packaged-application\application [_components:protected] => Array ( [Default_Controller_Action_Helper] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/controllers/actions/helpers [Default_Module] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/modules [Default_Model_DbTable] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models/DbTable [Default_Model_Mapper] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models/mappers [Default_Form] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/forms [Default_Model] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models [Default_Plugin] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/plugins [Default_Service] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/services [Default_View_Helper] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/views/helpers [Default_View_Filter] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/views/filters ) [_defaultResourceType:protected] => model [_namespace:protected] => Default [_resourceTypes:protected] => Array ( [actionhelper] => Array ( [namespace] => Default_Controller_Action_Helper [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/controllers/actions/helpers ) [module] => Array ( [namespace] => Default_Module [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/modules ) [dbtable] => Array ( [namespace] => Default_Model_DbTable [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models/DbTable ) [mappers] => Array ( [namespace] => Default_Model_Mapper [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models/mappers ) [form] => Array ( [namespace] => Default_Form [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/forms ) [model] => Array ( [namespace] => Default_Model [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models ) [plugin] => Array ( [namespace] => Default_Plugin [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/plugins ) [service] => Array ( [namespace] => Default_Service [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/services ) [viewhelper] => Array ( [namespace] => Default_View_Helper [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/views/helpers ) [viewfilter] => Array ( [namespace] => Default_View_Filter [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/views/filters ) ) ) ) ) [_environment:protected] => [_optionKeys:protected] => Array ( [0] => phpsettings [1] => includepaths [2] => bootstrap [3] => resources [4] => deviceprofiling [5] => pluginpaths [6] => autoloadernamespaces ) [_options:protected] => Array ( [phpSettings] => Array ( [log_errors] => 1 [date] => Array ( [timezone] => America/New_York ) [display_startup_errors] => 0 [display_errors] => 1 [error_reporting] => 32767 [error_log] => C:\LodgingPhp\com-ui-php\target/logs/php_error.log ) [includePaths] => Array ( [library] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/../library ) [bootstrap] => Array ( [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/Bootstrap.php [class] => Bootstrap ) [resources] => Array ( [frontController] => Array ( [controllerDirectory] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/controllers [moduleDirectory] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/modules ) [layout] => Array ( [layoutPath] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/layouts/scripts ) [setsystemtime] => Array ( [load] => ) [session] => Array ( [strict] => ) [modules] => Array ( [0] => api [1] => tickets [2] => events [3] => passes [4] => plan [5] => resortaddons [6] => debugutils [7] => visa-instant-credit ) [view] => [log] => Array ( [logConfig] => /configs/log.ini ) [stats] => Array ( [serviceLogLevel] => INFO [requestResponseLogLevel] => DEBUG [viewLogLevel] => INFO [actionLogLevel] => INFO [appLogLevel] => INFO [memoryLogLevel] => DEBUG ) [serviceSuccessLog] => Array ( [logConfig] => /configs/serviceSuccessLog.ini ) ) [deviceprofiling] => Array ( [cookieName] => WDPROView [timeToLive] => 604800 [cookiePath] => / [enabled] => 1 [routeBlackList] => Array ( [0] => /api [1] => /utils ) ) [pluginpaths] => Array ( [PEP_Stats_Resource_] => PEP/Stats/Resource [PEP_Application_Resource_] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/../library/PEP/Application/Resource [Default_Resource_] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/resource ) [autoloadernamespaces] => Array ( [0] => WDPRO_ [1] => Zend_ [2] => PEP_ [3] => controllers_helpers_ [4] => Guzzle [5] => Symfony ) ) [_pluginLoader:protected] => [_pluginResources:protected] => Array ( [layout] => Array ( [layoutPath] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/layouts/scripts ) [setsystemtime] => Array ( [load] => ) [session] => Array ( [strict] => ) [modules] => Array ( [0] => api [1] => tickets [2] => events [3] => passes [4] => plan [5] => resortaddons [6] => debugutils [7] => visa-instant-credit ) [view] => [log] => Array ( [logConfig] => /configs/log.ini ) [stats] => Array ( [serviceLogLevel] => INFO [requestResponseLogLevel] => DEBUG [viewLogLevel] => INFO [actionLogLevel] => INFO [appLogLevel] => INFO [memoryLogLevel] => DEBUG ) [serviceSuccessLog] => Array ( [logConfig] => /configs/serviceSuccessLog.ini ) [frontcontroller] => Zend_Application_Resource_Frontcontroller Object ( [_front:protected] => [_bootstrap:protected] => Bootstrap Object *RECURSION* [_options:protected] => Array ( [controllerDirectory] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/controllers [moduleDirectory] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/modules ) [_skipOptions:protected] => Array ( [0] => options [1] => config ) ) ) [_run:protected] => Array ( [0] => autoload ) [_started:protected] => Array ( [core] => 1 ) ) [_options:protected] => Array ( ) [_skipOptions:protected] => Array ( [0] => options [1] => config ) ) 

I need to remove the setsystemtime part:

[setsystemtime] => Array ( [load] => )

but I cannot reach it, I have tried casting the array and later making an array_search but I get: "It brings Array to string conversion":

$coreBootstrap = array_merge(array_diff((array) $coreBootstrap, array('setsystemtime')));

Also I tried the following:

   $a = serialize($coreBootstrap);
   $x =json_encode($a);
   $x= str_replace('s:13:\"setsystemtime\";a:1:{s:4:\"load\";s:1:\"1\";}', "", $x);
   $a = json_decode($x, true);
   $a = unserialize($a); // this brings an error and page doesnt load
  // $logger->info($a);
   $a = (object) $a;
     $logger->info($x);
 //    $a->init(); 
   $coreBootstrap->init();

Also It's php 5.4.4

Any ideas? Thank You!

  • 写回答

1条回答 默认 最新

  • dsa2c2255888 2016-10-19 03:59
    关注

    Instead of trying to cast the array, why not cast $coreBootstrap to an array and unset the index, and then serialize or cast it back to an object?

    // this should be done for each subindex that is also an object.
    $a = (array) $coreBootstrap;
    unset($a[..the index..]);
    $a = (object) $a;
    

    One can also try to go for a complete recursive conversion, but this might not be wanted:

    $a = json_decode(json_encode($coreBootstrap, JSON_FORCE_OBJECT), false);
    

    Its just better to do this specifically when dealing with a large array containing array's and objects.

    $a = (array) $coreBootstrap->objectvar->objectvar;
    unset($a[idofindex]);
    $a = (object) $coreBootstrap->objectvar->objectvar;
    $coreBootstrap->objectvar->objectvar = $a;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 MATLAB动图的问题
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名